listBox1.Items[listBox1.SelectedIndex] = "afx"; //如果当前选中的项也是AFX则这样子修改不了内容 listBox会认为 afx和AFX是相同的内容
//假设当前要修改的行内容是AFX 然后将它修改为afx
//会发现这样做没反应 listBox1.Items[listBox1.SelectedIndex] = "afx";
//换成下面的代码则正常操作 private void button1_Click(object sender,EventArgs e) { string s = "afx"; int index = listBox1.SelectedIndex; listBox1.Items[index] = s; //这句竟然不是多余的 if (s == listBox1.Items[index].ToString()) { listBox1.Items.RemoveAt(index); listBox1.Items.Insert(index,s); listBox1.SelectedIndex = index; } }
2020年7月25日 12:33:15
原文:https://www.cnblogs.com/xe2011/p/13376339.html