Right now I'm displaying data from a dataset and the selection mode is FullRowSelect
. Any way to set this?
The DataGridView.SelectionMode
property will do that for you through the DataGridViewSelectionMode
enumeration.
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
As for the rest of your question, I think further details are required. What kind of behaviour are you after?
EDIT #1
As per your comment:
After I clicked in a row a new form is opened. The problem is that every time the timer is enabled the populate_DatagridView method is called and the selected row is located in the first row rather that keep selected the row clicked.
One solution could be the following:
private _dataGridViewRowSelectedIndex;
private void dataGridview1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
DataGridView dgv = (DataGridview)sender;
if (dgv.Rows.GetRowState(e.RowIndex) == DataGridViewElementStates.Selected)
_dataGridViewRowSelectedIndex = e.RowIndex;
// Open your form here...
// And when your form returns...
// Set the selected index like so
dgv.Rows[_dataGridViewRowSelectedIndex].Selected = true;
}
Does this help you out?