1
votes

I'm currently working on a Winforms project that has a datagridview in it, on which I display my users list. I want to add (in addition to the basic parameters that are all int and string etc.) a button in the last column that will have an OnClick listener. Problem is, I don't have a dataSource and I'm working with a BindingList and BindingSource object; I've tried to add a button variable to the class that's displayed in the grid and it didn't work; I couldn't find a way to convert Button to DataGridViewCell. How do I add a button at the end of every row?

code:

var bindingList = new BindingList<userDisplay>(usersListDGV); //userDisplay has int and string variables
var source = new BindingSource(bindingList, null);
usersDGV.DataSource = source;
1

1 Answers

2
votes

I suggest you set your grid to AutoGenerateColumns = false then add a column for each of the fields in your bindingsource and set the DataPropertyName appropriately so the column is bound. You can do this through the UI or in code. Then add a DataGridViewButtonColumn and handle the CellClick or EditingControlShowing event to wire up the click handler as mentioned here.