Solved

Sort column when clicking header in DataViewGrid

Posted on 2009-04-04
3
244 Views
Last Modified: 2013-11-27
I have a DataGridView that pops up a dialog when a cell is clicked. The dialog displays information relevant to the selected row.

If I click the column header, the dialog is displayed even though I only want the DataGridView to be sorted. Once I close the dialog, the DataGRidView is displayed sorted.

How can I avoid displaying the dialog when the column header is displayed?
0
Comment
Question by:jindalee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Ramone_Hamilton
ID: 24070585
In which event are you calling your method to dsplay the dialog?
0
 
LVL 6

Accepted Solution

by:
Ramone_Hamilton earned 500 total points
ID: 24070639
Here's an example of how you can fix this.  I'm assuming you are usin the CellContentClick even.  Simple add an if check for e.RowIndex == -1, which represents the headerrow.
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
            }
            else
            {
                MessageBox.Show("Hello");
            }
        }

Open in new window

0
 
LVL 1

Author Closing Comment

by:jindalee
ID: 31566710
I'm using VB but is was easy to translate the C into VB

if e.RowIndex > -1 then
    do stuff
end if

Thank you
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question