【问题标题】:How to create more than 1 check box in ListView object?如何在 ListView 对象中创建多个复选框?
【发布时间】:2023-03-15 02:38:01
【问题描述】:

我正在使用ListWiew,它已选中选中的属性,因此它在第一列的每个项目上都有一个复选框。现在,我还想在第二列上有另一个复选框,但在我的列表视图的属性中找不到任何有用的复选框。

我该怎么做?

【问题讨论】:

  • ListView 不支持。任何网格控件都可以。

标签: c# listview checkbox subitem


【解决方案1】:

为什么不使用 DataGrid?它可以根据需要在任何地方显示尽可能多的复选框:)

            dataGridView1.ColumnCount = 3;
            dataGridView1.Columns[0].Name = "Product ID";
            dataGridView1.Columns[1].Name = "Product Name";
            dataGridView1.Columns[2].Name = "Product Price";

            string[] row = new string[] { "1", "Product 1", "1000" };
            dataGridView1.Rows.Add(row);
            row = new string[] { "2", "Product 2", "2000" };
            dataGridView1.Rows.Add(row);
            row = new string[] { "3", "Product 3", "3000" };
            dataGridView1.Rows.Add(row);
            row = new string[] { "4", "Product 4", "4000" };
            dataGridView1.Rows.Add(row);

            DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
            dataGridView1.Columns.Add(chk);
            chk.HeaderText = "Check Data";
            chk.Name = "chk";
            dataGridView1.Rows[2].Cells[3].Value = true;

【讨论】:

  • 这可能需要我一些时间才能从 ListView 切换到数据网格,但这可能是值得的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多