views:

25

answers:

3

Hello everyone,

I am currently working on my datagridview which is being populated by a stored procedure's query from the database. My question is how can I select the whole row even though I only click one cell?

Example, there are four columns returned by the stored procedure. So basically the datagridview will present to me data in four columns. If I select row 2 of column 3, is it possible that the action will not only highlight the row2 column 3 but the whole row 2?

Thanks very much!

+1  A: 
DataGridView1.FirstDisplayedScrollingRowIndex = DataGridView1.Rows(counter).Index

DataGridView1.Refresh()

DataGridView1.CurrentCell = DataGridView1.Rows(counter).Cells(1)

DataGridView1.Rows(counter).Selected = True

More: http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/47e9c3ef-a8de-48c9-8e0d-4f3fdd34517e/

redhatlab
+1  A: 

You can set the SelectionMode of your datagridview to FullRowSelect:

dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
Lee Sy En
right thanks :) but, how will I get the selected index of the row i selected? thanks :)
Kim Rivera
on the click event from the row, it returns in the parameter "e" has property called "RowIndex" or something like that, sorry I don't know for sure cause I am away from any VS right now. But follow this glue I think you gonna find that.
Leo Nowaczyk
A: 

There is a DataGridView.SelectionMode property you can set to fullrowselect.

rerun