2011-08-02 47 views
0

我有四个datagridviews和一个文本框,我想为每个单元显示不同的消息,用户可以在其中一个dgvs中选择。任何想法都欢迎!如何在每次在datagridview中选择单个单元格时显示消息?

+1

更多细节将有助于改善这种大小写,是否要显示一个消息框,在文本框中显示一条随机消息,或者我想,在文本框中显示给定DGV中所选单元格的内容? – Coops

+0

第二个在文本框中显示文本。该文本将是关于用户选择的单元的一些信息。 – Karapapas

+0

对不起这些信息是如何链接到选定的单元格? – Coops

回答

3

我更喜欢在代码如下指定大多数事件处理程序,而不是使用这使代码在form.designer.cs的GUI但是这是个人喜好

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

非常感谢你!正是我期待的!只需在关于事件处理程序的答案中添加一个描述,该事件处理程序将发送到form.designer.cs,而不是在form.cs的某个地方..花了我一段时间才找出。 – Karapapas

+0

公平点,它只是我的偏好,所以我可以清楚地看到通过在代码中进行的所有事情为我节省了时间,但花费了更多的时间在个人之上。 – Coops

+0

对不起,你是对的!它的工作方式也是如此! – Karapapas

相关问题