Select DatagridView first column Rows from Button click.

Abdoul Rahim

Member
Joined
Oct 16, 2017
Messages
15
Programming Experience
Beginner
Hi guys. I have a button and a datagridView fill with data in my form. So , is it possible to automatically select the datagridview first row columns (Current Row) when the button is clicked?
 
It's not clear what you mean. Remember that "selected" and "current' mean different things in a DataGridView. Do you mean that you want to select all the cells in first column? Do you want to make the first cell in the current row the current cell? Do you want something else?
 
If you actually mean selected then you get a reference to that cell and set its Selected property to True. To get that reference, you get the Cells property of the CurrentRow and get the item at index 0.
 
Thank very much. ..
But please can i have any code line which can enable me to better understand how toi set cell crurent row property to index 0..
 
get the Cells property of the CurrentRow and get the item at index 0
var cell = theDataGridView.CurrentRow.Cells[0];

get a reference to that cell and set its Selected property to True
cell.Selected = true;

or shorter:
theDataGridView.CurrentRow.Cells[0].Selected = true;
 
Back
Top Bottom