Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid - Right Click Row Select

Status
Not open for further replies.

Mongr1l

Programmer
Mar 6, 2006
179
US
Hello.

Can any finish the following code?
Code:
Private Sub dataGrid1_MouseUp(byval sender as System.Object, byval e as System.EventArgs) handles dataGrid1.MouseUp

  If e.Button = MouseButtons.Right then

  '''''''''' Code that selects the grid row the mouse    cursor is currently over ''''''''''''''''


  End if
End Sub

I'm using Dot Net 1.1. And I'm using their generic data grid. (I know. It sucks. Buy a real one).

Thanks in advance

- mongril
 
...

In case you're wondering why, I'm trying implement a context menu that lets the user delete a selected record.

This is ok if the record selected is the same one the cursor happens to be over.

 
Ok, I think I'm close. I found how to select a row by right clicking the Data grid.

It goes as follows:
Code:
Private Sub dataGrid1_MouseUp(byval sender as System.Object, byval e as System.EventArgs) handles dataGrid1.MouseUp



  If e.Button = MouseButtons.Right then
    Dim pt = New Point(e.x, e.y)
    Dim hti as DataGrid.HitTestInfo = dataGrid1.HitTest(pt)

    dataGrid1.CurrentCell = New DataGridCell(hti.row, hti.column)
    dataGrid1.Select(hti.Row)

  End if
End Sub


This does select the row the mouse is over. However, now I have new problem: The context menu pops up *before* the row is selected.

I'm thinking maybe I ought to use a mouse down or mouse hover event... possibly giving my grid a "rollover" effect, which I'm not sure I want.

Suggestions?

- mongril
 
Ok, I solved it.

The solution is as to use the grid mouse down event.


- mongril
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top