angireddy
asked on
How can I select a row in the datagrid
How can I highlight the whole row in a datagrid when we click, the click can be right, left, double and also any coloumn. Please let me know how I can do this. Very urgent
ASKER
No, I don't want to select the data from each cell. I want to highlight the whole row when we click on any coloumn of that row.
To highlight a row use the Select method...
dgRecords.Select(dgRecords .CurrentRo wIndex)
You can fire this from the click event which will include a double-click, right click etc...
Racin
dgRecords.Select(dgRecords
You can fire this from the click event which will include a double-click, right click etc...
Racin
My bad...
That doesn't work...
But this does in the MouseUp Event:
Private Sub dgItems_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles dgItems.MouseUp
Dim hti As System.Windows.Forms.DataG rid.HitTes tInfo
Try
With dgItems
hti = .HitTest(e.X, e.Y)
If hti.Row >= 0 Then 'highlight row clicked on
.CurrentRowIndex = hti.Row
.Select(.CurrentRowIndex)
End If
End With
Catch ex As Exception
DisplayMessage.ErrorMessag e("Error in MouseUp on Grid: " & ex.Message)
End Try
End Sub
Racin
That doesn't work...
But this does in the MouseUp Event:
Private Sub dgItems_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
Dim hti As System.Windows.Forms.DataG
Try
With dgItems
hti = .HitTest(e.X, e.Y)
If hti.Row >= 0 Then 'highlight row clicked on
.CurrentRowIndex = hti.Row
.Select(.CurrentRowIndex)
End If
End With
Catch ex As Exception
DisplayMessage.ErrorMessag
End Try
End Sub
Racin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops, didnt know the answer before mine was there...
anyways, thought i should cite my work, got this from
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q689q
anyways, thought i should cite my work, got this from
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q689q
The code I gave you does not mean that you have to click on each cell.
Just the cell in that row and you can break downthe answer by selecting each cell value that you need.
Just the cell in that row and you can break downthe answer by selecting each cell value that you need.
ASKER
Thanyou bramsquad, planocz and racinran
I'm curious... what was wrong with my anwser compared to bramsquad?
ASKER
hahaha, don't get mad, even your answer is also correct. But both of your answers came at the same time probably and I was in a hurry to insert this code in my project. Both of your answers are the same. Sorry if I hurt you by accepting bramsquad answer.
not hurt ... just wanting to know ... I'm new here and am just trying to gain enough points to fully participate in the site.
No problem... :)
Racin
No problem... :)
Racin
Private Sub datagrid_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
Try
txtQty.Text = dgInventory.Item(dgInvento
txtDescription.Text = dgInventory.Item(dgInvento
Catch ex As InvalidCastException
'Skip DBNULL
Catch ex As SystemException
MsgBox(ex.StackTrace & ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub