Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day

I have created a Form with a Datagridview on it. I want to Right click on a specefic heading on my Datagridview and it open a new form.

I have written the following code on the ColumnHeaderMouseClick Event on the Datagridview.

C#
private void dtgAllIngdetTerminals_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
     {
         if (e.Button == MouseButtons.Right)
         {
if (dtgAllIngdetTerminals.Columns["TerminalID"].HeaderText == "TerminalID")
             {
                 frmFilter frmthree = new frmFilter();
                 frmthree.ShowDialog();
             }
             }
         }



At the moment, when I right click on any heading in the DatagridView it is opening a new form. Any suggestions where my code is incorrect?
Posted
Updated 15-Feb-12 23:58pm
v2
Comments
Shahin Khorshidnia 16-Feb-12 5:56am    
You said: "... it must go to a new Form."
And "... it is opening a new form"

Ok, What's the problem?
Please improve your question to be more clear.
JacoBosch 16-Feb-12 6:03am    
The problem what I have is, when I right click any heading on my Datageidviews it is going to a new form. I want to right click on specefic headings on my datagridview and then it must go to a new form. The problem is not going to a new form, the problem is, I want to right click on specefic headings on my datagridview and just those specefic headings must be able to go to a new form. Not every heading that I right clicked must go to a new Form.

1 solution

Replace
C#
if (dtgAllIngdetTerminals.Columns["TerminalID"].HeaderText == "TerminalID")


with

C#
if (dtgAllIngdetTerminals.Columns["TerminalID"].Index == e.ColumnIndex)


If your problem is solved you may accept and vote the solution, otherwise post your queries, so that other users can know

PES
 
Share this answer
 
Comments
JacoBosch 16-Feb-12 6:34am    
Thanx.
ProEnggSoft 16-Feb-12 6:42am    
Thanks:)
Shahin Khorshidnia 16-Feb-12 7:46am    
+5
ProEnggSoft 16-Feb-12 10:04am    
Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900