【问题标题】:How to display a message everytime a single cell is selected in a datagridview?每次在datagridview中选择单个单元格时如何显示消息?
【发布时间】:2016-09-27 03:47:13
【问题描述】:

我有四个数据网格视图和一个文本框,我想为用户可能在其中一个 dgv 中选择的每个单元格显示不同的消息。欢迎任何想法!!!

【问题讨论】:

  • 在这种情况下,更多细节会有所帮助,您是要显示消息框,还是要在文本框中显示随机消息,或者我正在考虑,显示给定 DGV 中选定单元格的内容在文本框中?
  • 第二个在文本框中显示文本。文本将是有关用户选择的单元格的一些信息。
  • 对不起,这个信息是什么,它是如何链接到所选单元格的?

标签: c# .net winforms datagridview richtextbox


【解决方案1】:

我更喜欢在下面的代码中指定大多数事件处理程序,而不是使用将代码放在 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
}

【讨论】:

  • 非常感谢!正是我想要的!只需在答案中添加有关事件处理程序的描述,该事件处理程序将转到 form.designer.cs 而不是在 form.cs 中的某个地方。我花了一段时间才找到......
  • 公平点,这只是我的偏好,所以我可以清楚地看到正在发生的一切,通过在代码中执行它可以节省我以后的时间,但在个人方面会花费更多的早期成本。跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-17
  • 2013-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多