Thursday, May 11, 2017

To assign actions to links that are in DataGridView cells using C#


Here is the code to show another form based on the value in the DataGridView selected cell. You need to create another form (form2) and will be displayed on clicking the cell that contains values in the If condition. Please change the new form name in the code accordingly.

private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
  if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
  { 
   string cellval = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
    if (cellval.Contains("google"))
     {
        Form2 frm = new Form2(this);
        frm.Show();
     }
   }


No comments:

Post a Comment

Augmented Reality and Virtual Reality

Here is the quick overview of Augmented Reality and Virtual Reality, also have explained how it is being used today and how it can chan...