Right Clicking on Datagridview + context Menu

1,786 views
Skip to first unread message

Karthizen

unread,
Oct 20, 2008, 9:59:30 AM10/20/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
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 link http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=196286&SiteID=1
which helps to right click & display the contents of a row. However I
need to first display the context menu and after that I need to
populate the row contents.



Regards,
Karthizen

Glenn

unread,
Oct 20, 2008, 12:37:07 PM10/20/08
to DotNetDe...@googlegroups.com
Just make the row contents menu a sub-menu of your context menu.
 
...Glenn

karthi keyan

unread,
Oct 20, 2008, 4:20:05 PM10/20/08
to DotNetDe...@googlegroups.com
Hi,
 
I solved it :-).... I found out the X & Y co-coordinates and diplayed it in context strip & then wrote the codings for displaying row contents in the click event of Contextmenu strip.
 
Regards,
karthikeyan

On Mon, Oct 20, 2008 at 10:53 PM, karthi keyan <kart...@gmail.com> wrote:
Hi Glenn,
 
Thanks for your suggestion.  I did the same & it is working, howeverI need to display the context menu strip at the location of the mouse when clicked(i.e., at the datagridview row), can you help me out in doing this?
 
Thanks & Regards,
Karthi

karthi keyan

unread,
Oct 20, 2008, 1:23:25 PM10/20/08
to DotNetDe...@googlegroups.com
Hi Glenn,
 
Thanks for your suggestion.  I did the same & it is working, howeverI need to display the context menu strip at the location of the mouse when clicked(i.e., at the datagridview row), can you help me out in doing this?
 
Thanks & Regards,
Karthi

On Mon, Oct 20, 2008 at 10:07 PM, Glenn <ke4kt...@gmail.com> wrote:

sallushan

unread,
Oct 21, 2008, 2:08:12 AM10/21/08
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

ankush mehta

unread,
Oct 21, 2008, 2:24:43 AM10/21/08
to DotNetDe...@googlegroups.com
DONT SEND ME MORE MAILSPLZ

Glenn

unread,
Oct 21, 2008, 7:09:19 AM10/21/08
to DotNetDe...@googlegroups.com
That's what I was going to say!!
 
...Glenn

Glenn

unread,
Oct 21, 2008, 7:10:23 AM10/21/08
to DotNetDe...@googlegroups.com
The unsubscribe from the group!
 
...Glenn

karthi keyan

unread,
Oct 21, 2008, 8:04:44 AM10/21/08
to DotNetDe...@googlegroups.com
Thanks a lot Tamiz

flatfilehater

unread,
Oct 21, 2008, 1:25:59 PM10/21/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
try on mouse move which opens a new form with the things you want to
do.



On Oct 20, 3: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

Cerebrus

unread,
Nov 3, 2008, 11:55:31 AM11/3/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Considering this to be an anguished request, I have changed your
subscription type to "No email". This means that you are still a
member of the Group, but will not receive any emails reflecting
activity within the Group. I have done this because you appear unsure
about how to do it yourself.

--
Cerebrus.
Group Moderator.

On Oct 21, 11:24 am, "ankush mehta" <ankush.meht...@gmail.com> wrote:
> DONT SEND ME MORE MAILSPLZ
>
> >> Karthizen- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages