Tools or button in DataGridView columns

0
0

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

  • You must to post comments
0
0

Hi Laurent,

depending on what you want to achieve, using the Control property of the HeaderCell could be a good option for you:

headercontrol

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

Attachment
  • Laurent
    if I had known it was so easy! It fits my use case perfectly. I just needed to calculate the position of the image to fit any header, no matter how high it is. Thanks so much for your help!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.