你在处理程序 datagridView1_CellFormatting() 中传递什么作为 DataGridViewCe

本文关键字:什么 DataGridViewCe 处理 程序 datagridView1 CellFormatting | 更新日期: 2023-09-27 18:30:37

我找到了更多关于被调用函数的文章,但我没有任何内容显示如何声明此事件并调用它。这是我用于该函数的内容:

void handler_dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

这是我想要完成的:

dataGridView1.CellStateChanged += new System.Windows.Forms.DataGridViewCellStateChangedEventHandler(dataGridView1.CellStateChanged += new System.Windows.Forms.DataGridViewCellStateChangedEventHandler(handler_dataGridView1_CellFormatting(this.dataGridView1, ***what goes here?***));

任何帮助非常感谢,谢谢!

你在处理程序 datagridView1_CellFormatting() 中传递什么作为 DataGridViewCe

连接事件时不传递任何参数。 它应该只是:

dataGridView1.CellStateChanged += handler_dataGridView1_CellFormatting;

大多数开发人员可能更喜欢缩短的版本:

dataGridView1.CellStateChanged += dataGridView1_CellFormatting;

然后,您必须创建代码块:

void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
  // do your formatting here with the information provided in the e variable.
}

如果您只键入dataGridView1.CellStateChanged +=后跟 Tab 键两次,Visual Studio 将自动为您创建该代码块。

或者,您也可以使用设计器为您连接和创建代码块,方法是单击"属性"框中的闪电图标并双击列出的事件之一。

如果在事件的属性窗口中双击,处理程序将挂接,如下所示:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
}