【发布时间】:2014-04-15 14:57:32
【问题描述】:
我有一个 ListBox 填充了一些项目,在 SelectedIndexChanged 事件中我倾向于删除任何现有的额外列(ID 1 和更大),之后,我创建一个新列并重新添加项目,但之前的项目保持不变,就像Add() 重载不起作用,这是我的代码:
if (listBox1.SelectedItems.Count > 0)
{
if (listView2.Columns.Count > 1)
{
int bla = listView2.Columns.Count;
for (int i = 1; i < bla; i++)
{
//MessageBox.Show("Removing Column: " + (bla - i));
listView2.Columns.RemoveAt(bla - i);
}
}
if (clmnnum[listBox1.SelectedIndex] == 1)
{
listView2.SuspendLayout();
listView2.Columns.Add("Primary Values", 90, HorizontalAlignment.Left);
listView2.ResumeLayout();
listView2.Items[0].SubItems.Add(exp[listBox1.SelectedIndex].ToString());
listView2.Items[1].SubItems.Add(hpe[listBox1.SelectedIndex].ToString());
listView2.Items[2].SubItems.Add(lve[listBox1.SelectedIndex].ToString());
listView2.Items[3].SubItems.Add(stre[listBox1.SelectedIndex].ToString());
listView2.Items[4].SubItems.Add(powe[listBox1.SelectedIndex].ToString());
listView2.Items[5].SubItems.Add(ende[listBox1.SelectedIndex].ToString());
}
}
ListBox 包含的项与每个 Array 中的项一样多(clmnnum、exp、hpe 等...)
【问题讨论】: