Hello,
I am especially excited about the possibility of having tools with most controls.
However, I noticed that datagridview headers can’t have them.
Is it possible to cheat to add a button next to the text of a column header in the datagridview?
I know I could use the Tools property of the DataGridView, but I would like to spare some space because I have a lot of datagrids to display. And a button alone on the top of the DataGridView looks ugly.
Thank you for your help
Hi Laurent,
depending on what you want to achieve, using the Control property of the HeaderCell could be a good option for you:
With the following code:
private void Page1_Load(object sender, EventArgs e) { PictureBox pic = new PictureBox(); pic.ImageSource = "icon-info"; pic.Size = new System.Drawing.Size(24, 24); pic.Padding = new Padding(0, 8, 0, 0); this.dataGridView1.Columns[0].HeaderCell.Control = pic; pic.Click += Pic_Click; } private void Pic_Click(object sender, EventArgs e) { AlertBox.Show("Clicked."); }
If you want to have more than one button in column header you could use a panel as control and put multiple pictures in it.
Hope that helps. If it does not please provide more information about what you want to achieve.
Best regards
Frank
Please login first to submit.