Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to programmatically generate a click on a DataGridView Row in C#

I have a DataGridView in a form and I want to programmatically click its first row. I have found code to select its rows or columns from code.

For eg.

datagridview.Columns[0].Selected = true;
datagridview.Rows[0].Selected = true;

However this code is not raising the click event on the datagridview. If any one has coded how to click a datagridview from code, please extend your kind help.

like image 310
Sumit Ghosh Avatar asked Aug 20 '10 16:08

Sumit Ghosh


1 Answers

Simply call the event handler method e.g.:

datagridviewRowClickedEventHandler(new object(), new eventargs());

If you use the sender or e parameters in the event handler then you will need to work out how to pass in the correct values.

like image 129
Ben Robinson Avatar answered Oct 19 '22 19:10

Ben Robinson