如何通过编码将复选框添加到 datagridview

发布于 2024-09-06 04:26:20 字数 351 浏览 5 评论 0原文

如何通过 Windows 窗体编码将 checkbox 添加到 datagridview

我有一个数据表,其中一列为value=true; 在另一个数据表中,我将该列设置为value='Checkbox'

因此如果我的值为true并且checkbox是默认数据表value 单元格必须替换为 checkbox selected true。这样,

如果默认情况下该值为 true,则应在该复选框中选中它。

how to add the checkbox to the datagridview from coding in windows form.

i have a datatable with one column as value=true;
and in another datatable i had settings for that column as value='Checkbox'

so if my value is true and checkbox is there the default datatable value cell has to be replaced with checkbox selected true. in that way

if the value is true by default it should be checked in that checkbox..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浊酒尽余欢 2024-09-13 04:26:20

如果您想添加带有复选框的列:

DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.Name = "X";
checkColumn.HeaderText = "X";
checkColumn.Width = 50;
checkColumn.ReadOnly = false;
checkColumn.FillWeight = 10; //if the datagridview is resized (on form resize) the checkbox won't take up too much; value is relative to the other columns' fill values
dataGridView1.Columns.Add(checkColumn);

If you meant to add a column with checkboxes:

DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.Name = "X";
checkColumn.HeaderText = "X";
checkColumn.Width = 50;
checkColumn.ReadOnly = false;
checkColumn.FillWeight = 10; //if the datagridview is resized (on form resize) the checkbox won't take up too much; value is relative to the other columns' fill values
dataGridView1.Columns.Add(checkColumn);
末が日狂欢 2024-09-13 04:26:20

UI

              Step1 : Select the dataGrid at the UI
              Step2: Select Edit Column
              Step3: Click on the column name in edit Columns Window
              Step4:Select column type = "DataGridViewCheckBoxColumn"
              Step5: click ok

我认为在数据网格视图中添加复选框列的最简单方法是从附加快照的
输入图像描述这里

I think the easiest way to add Checkbox column in datagrid view is from the UI

              Step1 : Select the dataGrid at the UI
              Step2: Select Edit Column
              Step3: Click on the column name in edit Columns Window
              Step4:Select column type = "DataGridViewCheckBoxColumn"
              Step5: click ok

Attached a snaphot
enter image description here

撩起发的微风 2024-09-13 04:26:20

对于此类问题,您只需通过设计器添加控件,然后查看 Visual Studio 在代码隐藏文件中执行的操作即可。

For these kind of questions you can just add the control through the designer and see what Visual Studio did in the code behind file.

难得心□动 2024-09-13 04:26:20

假设您的意思是如何动态地将复选框列添加到 DataGridView 中:

DataGridViewCheckBoxColumn col = new DataGridViewCheckBoxColumn();
... // set properties as needed here
dataGridView1.Columns.Add(col);

Assuming that you mean how to add a checkbox column to a DataGridView dynamically:

DataGridViewCheckBoxColumn col = new DataGridViewCheckBoxColumn();
... // set properties as needed here
dataGridView1.Columns.Add(col);
兲鉂ぱ嘚淚 2024-09-13 04:26:20

您可能还需要设置 TrueValueFalseValue

officeCheckBoxColumn.TrueValue = 1;
officeCheckBoxColumn.FalseValue = 0;

我想知道是否有办法默认选中所有或取消选中所有 CheckBox

you may also need to set the TrueValue and FalseValue

officeCheckBoxColumn.TrueValue = 1;
officeCheckBoxColumn.FalseValue = 0;

I am wondering if there is way to check all or uncheck all CheckBox by default?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文