Selecting a row and the values in the cells

  • Thread starter Thread starter thewanz
  • Start date Start date
T

thewanz

Hello,
I would like to take the values contained in columns of a selected row and
display them in textboxes for editing. When I dbl click the datagridview
control it creates an event handler for the selected cell. Isn't there a
specific event handler for a selected row?

Wnz
 
Firstly, you may have already know you can make cell, row or column of
DataGridView select-able. In your case, make sure the DataGridView's
SelectionMode is set to RowHeaderSelect, or FullRowSelect.

Then, you can handle SelectionChanged event:

private void DataGridView1_SelectionChanged(...)
{
if (DataGridView1.SelectedRows.Count==0) return;

//Do something with the SelectedRows, it could be one row, or multiple
rows. For example:

Label1.Text=DataGridView1.SelectedRows[0].Cells[0].Value.ToString();
...
}
 
Excellent! This works, thanks for the tip on the selection mode, too!
Cheers,
Wnz

Norman Yuan said:
Firstly, you may have already know you can make cell, row or column of
DataGridView select-able. In your case, make sure the DataGridView's
SelectionMode is set to RowHeaderSelect, or FullRowSelect.

Then, you can handle SelectionChanged event:

private void DataGridView1_SelectionChanged(...)
{
if (DataGridView1.SelectedRows.Count==0) return;

//Do something with the SelectedRows, it could be one row, or multiple
rows. For example:

Label1.Text=DataGridView1.SelectedRows[0].Cells[0].Value.ToString();
...
}

thewanz said:
Hello,
I would like to take the values contained in columns of a selected row and
display them in textboxes for editing. When I dbl click the datagridview
control it creates an event handler for the selected cell. Isn't there a
specific event handler for a selected row?

Wnz
 
Back
Top