Click here to Skip to main content
15,888,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts,
I have a grid view and on clicking the cell i am accessing the id of that row.my problem is when i am clicking on the header am getting an exception..:(
Is there any way to disable click event on header..??
How to solve this... ? ? ?
Posted
Comments
OriginalGriff 5-Aug-14 5:56am    
What exception?
Any message? Code?

Hi HK33,

Although your question is quite "BAD" I try to start the guessing to work out what may be your problem. You are expecting someone to "work/think" for you, but you don't bother to formulate your question with a little effort - see OriginalGriffs comment. But with this "behaviour" you are not alone on this forum - I just can't get "used" to it...

That said, let's try to find your Problem:

I assume (those things you didn't think someone should know in order to help you):
* You use a System.Windows.Forms.DataGridView
* You are using the CellClick Event of your System.Windows.Forms.DataGridView
* Your exception happens when you try to get a cell with the indices you got from the EventArgs inside a CellClick handler (method)

So the trick could be just to add some logic to your handler.

C#
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    // No row was clicked (e.g. Header)
    if (e.RowIndex < 0)
    {

    }
    // No column was clicked (e.g. RowHeader)
    else if (e.ColumnIndex < 0)
    {

    }
    // valid cell
    else
    {
    }
}


If this does not solve your problem try to improve your question and show the problematic/relevant code.

Kind regards

Johannes
 
Share this answer
 
Hello,
You can handle it on row click event.
write code on row click or cell click event
e.handle=false;
 
Share this answer
 

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