gpt4 book ai didi

c# - 如何触发创建的复选框更改事件 C#

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:33 25 4
gpt4 key购买 nike

我在 gridview 中创建了这些复选框,以允许我的用户选择多行。我的问题是当单击复选框时,它们应该为每个单击的复选框存储信息。我在里面放置了断点,事件从未被触发。这是我需要调用的东西才能运行此事件吗?我的印象是它就像任何其他事件一样,它只是在触发它时运行。我还没有找到针对此类问题的通用帮助,这似乎是更具体的问题。您是否有任何关于如何让我的事件正确触发的帮助或建议?

在表单加载时建立

ckBox = new CheckBox();
//Get the column header cell bounds
Rectangle rect = this.dropdeadGridView.GetCellDisplayRectangle(0, -1, true);
ckBox.Size = new Size(18, 18);
//Change the location of the CheckBox to make it stay on the header
ckBox.Location = rect.Location;
ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
//Add the CheckBox into the DataGridView
this.dropdeadGridView.Controls.Add(ckBox);

然后这是我在 chkbox_CheckChanged 事件中声明发生的事情

var rows = dropdeadGridView.Rows;

for (int j = 0; j < this.dropdeadGridView.RowCount; j++)
{
this.dropdeadGridView[0, j].Value = this.ckBox.Checked;

bool checkBoxValue = Convert.ToBoolean(dropdeadGridView.Rows[5].Cells[1].Value);
if (checkBoxValue)
{
values += rows[j].Cells[2] + ",";
CurrentOrders = values;
}
}
this.dropdeadGridView.EndEdit();

最佳答案

希望你使用的是windows应用程序

http://csharp.net-informations.com/datagridview/csharp-datagridview-checkbox.htm

此链接告诉您如何在 gridview 中添加复选框。更改选择时,将触发 afteredit、validateedit 等网格事件。

我们通过检查列号(如果列号与复选框列号匹配)在那里进行编码,在那里执行您在事件中提到的操作

我对 winforms 的经验较少,我只使用 C1FlexGrid(Windows 网格中也有等效项)

关于c# - 如何触发创建的复选框更改事件 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24152523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com