当表中有多个列时,如何在datagridview上触发click事件?

时间:2014-02-24 17:27:59

标签: visual-studio-2010

public void Form1_Load(object sender, EventArgs e)
{
   con = new SqlConnection("server=ABHINAVPC;database=timtable;trusted_connection=true");
   con.Open();
   ds = new DataSet(); 
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    DataGridViewCell cell =(DataGridViewCell)dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];
     if (cell.ValueType.ToString() == "Abhinav")
     {
         MessageBox.Show("Right Name");
     }
     else
     {
         MessageBox.Show("Wrong Name");
     }
  }
}

0 个答案:

没有答案