Click here to Skip to main content
15,915,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void dataGridView2_Click(object sender, DataGridViewCellEventArgs e)
        {
                DataGridViewImageCell cell = (DataGridViewImageCell)
                dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];
                if (cell.Value=="sewagram express")
                {
                    SqlCommand cm1 = new SqlCommand("select * from sewagram", con);
                    DataTable dth = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter(cm1);
                    da.Fill(dth);
                    dataGridView1.DataSource = dth;
                }
        }
Posted
Updated 22-Feb-14 2:08am
v2
Comments
CHill60 22-Feb-14 8:09am    
So what is your question? Are you saying this code is never fired?
Abhinav Chaudhary 22-Feb-14 8:11am    
I want that when i click on the item sewagram it must fire the code of if statement....and my code is not doing that...can you please help me...
What is cell.Value when you debug?

1 solution

sir, as your heading say "how to fire click event for datagridview cells" and you have already made the function
private void dataGridView2_Click(object sender, DataGridViewCellEventArgs e)


if still dataGridView2_Click is not firing on click event of datagridview you should go to the Event's of datagridview -> check if "dataGridView2_Click" is written in front of the Click event
 
Share this answer
 
Comments
Abhinav Chaudhary 23-Feb-14 3:12am    
Sir,But its not working...i want that when i click on a particular cell named as "sewagram express" it should fire the code....sewagram express is a item in the datagridview table
agent_kruger 23-Feb-14 4:38am    
Then right on CellClick event.
agent_kruger 23-Feb-14 4:39am    
"Click" event is for click on datagridview and "CellClick" is for clicking on cell of a datagridview.
Abhinav Chaudhary 23-Feb-14 6:10am    
okay sir...but my code is not working properly...can you please check it...
agent_kruger 23-Feb-14 8:11am    
sir, did you write on the CellClick event?

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