sallushan
unread,Oct 21, 2008, 2:08:12 AM10/21/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
The link you have given works fine, but the following is better,
Private Sub DataGridView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
Dim ht As DataGridView.HitTestInfo
ht = Me.DataGridView1.HitTest(e.X, e.Y)
If ht.Type = DataGridViewHitTestType.Cell Then
Me.DataGridView1.CurrentCell =
Me.DataGridView1(ht.ColumnIndex, ht.RowIndex)
End If
End If
End Sub
Here we have used the "CurrentCell" property.
Now comming to your question regarding the ContextMenu. You can define
ContextMenu for the whole DataGridView using its "ContextMenuStrip"
property, but then you will get the Menu whenever you right click
anywhere on DataGridView (on column header, row header, etc.). Since
we need to show the menu when user right clicks on a Row, therefore we
can define the ContextMenu for Row. Use the "ContextMenuStrip" member
of "RowTemplate" property of DataGridView control.
Note that in DataGridView control we can define a different
"ContextMenuStrip" for individual Columns/Rows/Cells. By defining the
ContextMenuStrip in RowTemplate makes that ContextMenu available for
all rows.
Reagards,
Arsalan Tamiz
On Oct 20, 6:59 pm, Karthizen <
karthi...@gmail.com> wrote:
> Hi,
>
> Hi,
>
> I have some 'n' number of records in a datagridview. I need to right
> click on a row to pop up a context menu, then I need to click a
> particular menu to display the contents of the row. Can you please
> give me some suggestions on how to solve it?
>
> I found this linkhttp://
forums.microsoft.com/MSDN/ShowPost.aspx?PostID=196286&SiteID=1