作者kevin8685 (最爱maki~!)
看板C_Sharp
标题[问题] 问一个listbox的删除问题@@
时间Sun Jun 13 22:02:29 2010
我想要写个商品管理的系统
这是我写在form的一段
SortedList product = new SortedList();
StreamReader item = new StreamReader("product.txt");
while (!item.EndOfStream)
{
string[] item2 = item.ReadLine().Split(' ');
product.Add(item2[0], item2[1] + "\t" + item2[2]);
BindingSource bs = new BindingSource();
bs.DataSource = product;
listBox1.DataSource = bs;
listBox1.DisplayMember = "Value";
listBox1.ValueMember = "Key";
listBox1.ClearSelected();
}
之後我想要
在按钮写一个"删除选取的项目"
可是一直出现
"已设定 DataSource 属性时,无法修改项目集合。"
这是我按钮的写法
while (listBox1.SelectedItems.Count != 0)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndices[0]);
}
请问怎麽修改@@
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.117.14.212
1F:→ andymai:找到答案了吗?其实那个错误从另一个角度来看也算是告知该 06/14 18:57
2F:→ andymai:怎麽做了~不能在设定後移除~那就把listBox1.DataSource拿 06/14 18:58
3F:→ andymai:出来转型之後再移除就好了~也不必再设回DataSource... 06/14 18:59