1

I am learning Windows Visual C# so I am new to this. I have this code for the cell click event for my DataGridView

 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
      con.  ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
      txtname.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
      txtlname.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
    }

The question is: Even how many times I click my DataGridView it's not firing my breakpoint. How to solve this?

9
  • Are you sure you are clicking on your cells in the grid? Because your code seems fine. Commented Feb 24, 2017 at 4:07
  • did you add event handler ? msdn.microsoft.com/en-us/library/dd553231.aspx it might be a bit easier to try it in VB.Net until you get used to event handlers Commented Feb 24, 2017 at 4:23
  • @MAdeelKhalid yes I am sure. After I click my DataGridView I want the data to be display in textboxes Commented Feb 24, 2017 at 5:08
  • Check your form designer and confirm that you got this this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);. Commented Feb 24, 2017 at 6:52
  • @Berkay I don't see anything like that in my designer Commented Feb 24, 2017 at 6:53

1 Answer 1

5

Like this,

You can reach properties by right clicking or pressing F4 after selecting datagridview.

enter image description here

After press lightining icon and double click to event that you like to handle.

enter image description here

Finally you will see this,

enter image description here

Hope helps,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.