I want to select row of previously selected rows after some event my code is as below.
int currentRow = dgvIcbSubsInfo.CurrentCell.RowIndex; //code to execute dgvIcbSubsInfo.Rows[currentRow].Selected = true;
after executing the code the preview will be as below. but i need to get the symbol >
in id = 1272741 (blue selection) and not in 1272737
To get the selected rows in a DataGridView controlUse the SelectedRows property. To enable users to select rows, you must set the SelectionMode property to FullRowSelect or RowHeaderSelect.
Answers. "Rows" is a property of the DataGridView that returns all the rows as a collection. For a particular Row, you can set the . Selected property to True (or False) to select (or unselect) that Row.
When a row is selected in a GridView control, use the SelectedRow property to retrieve the GridViewRow object that represents that row. This is the same as retrieving the GridViewRow object at the index specified by the SelectedIndex property from the Rows collection.
Probably you might have taken a look at the DataGridView.CurrentRow Property, which is a read-only property:
Gets the row containing the current cell.
But in the remarks section, there is written:
To change the current row, you must set the
CurrentCell
property to a cell in the desired row.
Also, from the DataGridView.CurrentCell Property, we find out that:
When you change the value of this property, the SelectionChanged event occurs before the CurrentCellChanged event. Any SelectionChanged event handler accessing the CurrentCell property at this time will get its previous value.
So, there is no need that you actually select the currentRow
becasue it will be selected when you set the CurrentCell
value (unless you have some code to be executed inside the current scope between the SelectionChanged
and CurrentCellChanged
events). Try this:
//dgvIcbSubsInfo.Rows[currentRow].Selected = true; dgvIcbSubsInfo.CurrentCell = dgvIcbSubsInfo.Rows[currentRow].Cells[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With