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 开发者_StackOverflowrow 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!
You can set the SelectionMode of your datagridview to FullRowSelect
:
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
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/
There is a DataGridView.SelectionMode property you can set to fullrowselect.
精彩评论