Add buttons in the DataGridView cell

2

I'm developing a Windows Form C # activity control application for a company, however I would need to display the activities as buttons within the GridView cell.

I've tried:

DataGridViewButtonColumn uninstallButtonColumn = new DataGridViewButtonColumn();
uninstallButtonColumn.UseColumnTextForButtonValue = true;
uninstallButtonColumn.HeaderText = "Delete/Edit";
uninstallButtonColumn.Name = "uninstall_column";
uninstallButtonColumn.Text = "Teste";

dgvPrincipal.Columns.Insert(1, uninstallButtonColumn);

This format allows only 1 button, when in fact there may be several buttons in the same cell.

And I've tried it too:

dgvPrincipal.Rows[0].Cells[0].DataGridView.Controls.Add(tbnTeste);

This inserts the button without any link with the cells.

Does anyone know a way? Type DataRowBound ... or something similar?

    
asked by anonymous 08.01.2015 / 18:16

1 answer

2

In my case this solved my problem ...

You can only use DataGridViewImageColumn and use the DataGridViewCellEventArgs event to check which cell was clicked.

Obs : In my case, I was needing two buttons on my DataGridView    one to edit the selected content and one to delete the item from the    selected line.

  • Step 1:   You must add 2 columns in your Grid , and set them as    DataGridViewImageColumn . Add the required images in each field.
  • Step 2:   Go to the events of Grid and double-click on the CellContentClick or CellClick field. Either way the difference is   that the first one will only be used if the user clicks on the   image within the cell. The second one will work when the user    click on the entire cell .
  • Step 3:   In the event of DataGridView , type the code below:

I hope I have helped ...

If it helped, do not forget to mark the answer as correct.

Great Hug!

    
27.08.2016 / 02:11