Selecting a row and the values in the cells

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
 
N

Norman Yuan

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();
...
}
 
T

thewanz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top