如果有一个按钮是“重命名字段”
有一个textbox 用来写你要改的名字
如何在事件中把选中的项的内容改掉?并且让它保持原来的索引位置。用什么方法?
private void resetname_Click(object sender, System.EventArgs e)
{
??????
}

解决方案 »

  1.   

    private void resetname_Click(object sender, System.EventArgs e)
    {
    if(listBox1.SelectedIndex > 0)
    {
    listBox1.Items[listBox1.SelectedIndex] = resetname.Text;
    }
    }
      

  2.   

    listBox1.SelectedIndex >= 0
      

  3.   

    private void resetname_Click(object sender, System.EventArgs e)
    {
    if(listBox1.SelectedIndex > 0)
    {
    listBox1.Items[listBox1.SelectedIndex] = resetname.Text;
    }
    }
    这个方法不行
      

  4.   

    private void resetname_Click(object sender, System.EventArgs e)
    {
    if(listBox1.SelectedIndex > 0)
    {
         listBox1.Items.RemoveAt(listBox1.SelectedIndex);
         Object XXX = resetname.Text;
         listBox1.Items.Add(XXX);
    }
    }
    看看可以不