Re: DataGridView Row Select
try this:
vb Code:
Private Sub DataGridView1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Selected = True
End If
End Sub
Re: DataGridView Row Select
I think he wants the whole row selected, not just the cell:
vb.net Code:
DataGridView1.Rows(e.RowIndex).Selected = True
Re: DataGridView Row Select
another alternative:
vb Code:
DataGridView1.currentcell = DataGridView1(e.ColumnIndex,e.RowIndex)
Re: DataGridView Row Select
Thanks Guys!
is using a while loop like this a bad idea, is their an easier/better way?
vb Code:
Private Sub Content_CellContentClick_1(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Content.CellMouseDown
Dim i As Integer = 0
While i < Content.Rows.Count
Content.Rows(i).Selected = False
i = i + 1
End While
If e.Button = Windows.Forms.MouseButtons.Right Then
Content.Rows(e.RowIndex).Selected = True
End If
End Sub
Re: DataGridView Row Select
Yep there is a better way, DataGridViews has a property called 'SelectedRows'. So instead of you looping through every row in the DataGridView you can just use that collection:
vb.net Code:
While Content.SelectedRows.Count > 0
Content.SelectedRows(0).Selected = False
End While
Both your code and mine does the same, but I'm just looping through the rows that are selected and making them not selected. ;)
Re: DataGridView Row Select
Quote:
Originally Posted by
The Little Guy
Thanks Guys!
is using a while loop like this a bad idea, is their an easier/better way?
vb Code:
Private Sub Content_CellContentClick_1(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Content.CellMouseDown
Dim i As Integer = 0
While i < Content.Rows.Count
Content.Rows(i).Selected = False
i = i + 1
End While
If e.Button = Windows.Forms.MouseButtons.Right Then
Content.Rows(e.RowIndex).Selected = True
End If
End Sub
or you could use my code from post #4, which will select the cell you click on + deselect the last cell, which with fullrowselect is what you want.