OldValue.Text=checkedListBox1.Items[checkedListBox1.SelectedIndex].ToString();########################################################就是这句,如果没有这句,就能顺利得删除checkedListBox1里得被选中得项,可是确无法在OldValue文本框中显示选中得项了!!怎么解决?
请问最终有没有删除成功?
假设有,只是OldValue中没有显示,则说明Items[checkedListBox1.SelectedIndex]并不能得到你想要的那个item中的text,你试着再看看items中有什么方法选项

解决方案 »

  1.   

    try:OldValue.Text=checkedListBox1.SelectedItem.ToString();
      

  2.   

    点击“删除”按钮后会出现异常中断,信息是:未处理的“System.NullReferenceException”类型的异常出现在 checklistBoxApp.exe 中。其他信息: 未将对象引用设置到对象的实例。我按照楼上得改成:OldValue.Text=checkedListBox1.SelectedItem.ToString();也不行的,怎么回事?是不是程序其他部分有问题,而错误不在这?
      

  3.   

    try:
    OldValue.Text = Convert.ToString(checkedListBox1.SelectedItem)
      

  4.   

    谢谢楼上的,搞定了。可是我不明白,这三句有什么不同?
    OldValue.Text=checkedListBox1.Items[checkedListBox1.SelectedIndex].ToString();原来的
    OldValue.Text=checkedListBox1.SelectedItem.ToString();BearRui的
    OldValue.Text = Convert.ToString(checkedListBox1.SelectedItem);你的
      

  5.   

    OldValue.Text=checkedListBox1.SelectedItem.ToString();BearRui的
    OldValue.Text = Convert.ToString(checkedListBox1.SelectedItem);你的这两句从本质上没区别,只是实现的方式不同而已.
    1,是使用checkedlistbox1.selecteditem.下面的方法
    2.是使用convert这个提供的方法.
    OldValue.Text=checkedListBox1.Items[checkedListBox1.SelectedIndex].ToString();原来的
    这一句看上去没什么区别?问题可能出在Items[checkedListBox1.SelectedIndex]具体,不是很清楚.
    很少这样用,一般就用前面的2种方法
      

  6.   

    checkedlistbox1是复选的!
    你选中多条时这么可能向文本框写入数据?