none
How can I get the value in cell when using DataGridView and dataGridView1_CellContentClick event.

    Question

  • I use the code  like this  but it does work.

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

    {

    // Show the customer order screen when the user clicks the link.

    if (e.ColumnIndex == 1 && e.RowIndex != -1 && !dataGridView1.Rows[e.RowIndex].IsNewRow)

    {

    string customerID = dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["CustomerID"].Value as string;

    if (customerID != null)

    {

    this.ViewOrders(customerID);

    }

    }

    }

    }

    Wednesday, April 26, 2006 6:42 PM

All replies

  • What happens when you run this?

    I am not sure how CurrentCellAddress works so can I suggest you change "dataGridView1.CurrentCellAddress.Y" with "e.RowIndex" when you set the string variable "customerID"?  Also, I am not sure if it matters, but you could try the "...Value.ToString" method instead of "as string".

    Hope this helps.

    Wednesday, April 26, 2006 10:43 PM