开发者

How to display a message everytime a single cell is selected in a datagridview?

开发者 https://www.devze.com 2023-03-24 12:43 出处:网络
I have four datagridviews and one text box and i want to display a differ开发者_StackOverflow社区ent message for every cell the user might select in one of the dgvs. Any idea is welcome!!!I prefer to

I have four datagridviews and one text box and i want to display a differ开发者_StackOverflow社区ent message for every cell the user might select in one of the dgvs. Any idea is welcome!!!


I prefer to specify most event handlers in code as below, as opposed to using the GUI which puts the code in the form.designer.cs but that is personal preference

public Form1()
 { 
      dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(populateTextBox());
      dataGridView2.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(populateTextBox());
      dataGridView3.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(populateTextBox());
      dataGridView4.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(populateTextBox());
 }

private void populateTextBox(object sender, DataGridViewCellEventArgs e)
{
    //code here
    //You can use e.Value (cell value data type dependant) if required
}
0

精彩评论

暂无评论...
验证码 换一张
取 消