Raditya Kurnianto
Raditya Kurnianto

Reputation: 744

Error happen when implementing datagridview cell click in C#

I have a problem with datagridview even handler, when I click at the cell i want the value in that cell send to text box, it was work but after i change something that i forgot it can't work. I've try to recreate the datagridview and its event handler but nothing. This is my code

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].ToString();
    }

enter image description here

do you have any idea to fix this problem?

Upvotes: 0

Views: 225

Answers (2)

estaban
estaban

Reputation: 1

private void gridview_CellClick(object sender, DataGridViewCellEventArgs e)
{
  int r = e.RowIndex;
  llenartextbox(r);
}

public void llenartextbox(int index)
{
  textbox.Text = gridview.rows[index].Cells["Cliente"].Value.ToString();
}

Upvotes: 0

Adil
Adil

Reputation: 148110

You need

 textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();

Upvotes: 1

Related Questions