Sort column when clicking header in DataViewGrid

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?
LVL 1
jindaleeAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Ramone_HamiltonConnect With a Mentor Commented:
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
 
Ramone_HamiltonCommented:
In which event are you calling your method to dsplay the dialog?
0
 
jindaleeAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.