将字符串变量插入datagridview.Columns [],其中需要string或int。 C#

时间:2016-09-06 08:16:34

标签: c# datagridview

自从我上次在这里问了一个问题已经很多年了,所以我希望能得到一些帮助。

foreach (object listItem in checkedListBox1.CheckedItems)
{
dataGridView1.Columns[].Visible = true;
}

我想将listItem插入到[]中。我可以看到它适用于:

["name"]
[1]

但我需要类似的东西 ["{0}", listItem]但我无法接受我需要的东西。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

如果checkboxlistlistItem,那么对已检查的项目执行foreach将意味着foreach (object listItem in checkedListBox1.CheckedItems) { dataGridView1.Columns[listItem.Name].Visible = true; } 将是一个复选框,而不是字符串。您将需要执行以下操作:

Planet?

有关我的评论here的更多详情,请参阅CheckedItems property