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 / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

dedect right click in DataGridView column header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrus - 14 Mar 2008 23:41 GMT
I need to capture mouse right click in DataGridView column header. I tried

class MyDataGridView: DataGridView {

protected override void
        OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e) {
....

OnColumnHeaderMouseClick  occurs when header is right or left-clicked by
mouse. DataGridViewCellMouseEventArgs does not provide
information which mouse button is pressed.

How to find when mouse is right-clicked in column header ?

Andrus.
Marc Gravell - 15 Mar 2008 10:44 GMT
Look at e.Button.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;

class Foo
{
   public string Name { get; set; }
   public DateTime DateOfBirth { get; set; }
}
static class Program
{
   [STAThread]
   static void Main()
   {
       Application.EnableVisualStyles();
       var list = new BindingList<Foo> {
           new Foo { Name = "Fred", DateOfBirth = DateTime.Now }
       };
       using (DataGridView grid = new DataGridView
       {
           Dock = DockStyle.Fill,
           DataSource = list
       })
       using (Form f = new Form {
           Controls = {grid}
       }) {
           grid.ColumnHeaderMouseClick += (sender, args) =>
           {
               f.Text = string.Format("Column {1}, Pressed: {0}",
args.Button, grid.Columns[args.ColumnIndex].DataPropertyName);
           };
           Application.Run(f);
       }
   }
}

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.