Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2007

Tip: Looking for answers? Try searching our database.

DataGrid / Context menu - HowTo

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
john coltrane - 21 Jan 2007 14:36 GMT
Can someone direct me to a reference that describes how to create a
context menu for a selected row in a datagrid? I have come across many
threads regarding context menus and datagrids but they all seem to be
how to modify the default behavior. I've gone through a couple of books

and many threads but none of these seem to discuss creating a context
menu for a given row. I did come across a thread that allowed me to
create a menu for the entire grid but that even allows for a context
menu outside of any rows.

thanks for your help

john
ClayB - 22 Jan 2007 10:58 GMT
You can catch a right click in the grid.MouseDown event and display the
contextmenu at that point if you are over the row where you want the
menu. Here is a little snippet that displays it over row 3. (Do not set
the dataGrid1.ContextMenu property if you want to only see the menu
over certain rows.)

private void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
    if(e.Button == MouseButtons.Right)
    {
        Point pt = new Point(e.X, e.Y);
        DataGrid.HitTestInfo info = dataGrid1.HitTest(pt);
        if(info.Row == 3)
        {
            this.contextMenu1.Show(this.dataGrid1, pt);
        }
    }
}

=================
Clay Burch
Syncfusion, Inc.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.