2011-10-08 35 views
3

嘿傢伙即時試圖讓它所以一旦我點擊刪除按鈕,它從列表視圖如何從列表視圖中刪除一個組合框項目

private void button2_Click_1(object sender, EventArgs e) 
     { 
      string sel = combobox.SelectedItem.ToString(); 
      repository.RemoveNumber(sel); 
      view.Items.Remove(sel); 
     } 

回答

2

我認爲,你可以這樣做

刪除組合框的文本
private void button1_Click(object sender, EventArgs e) 
    { 
     if (comboBox1.SelectedItem != null) 
     { 
      foreach (ListViewItem item in listView1.Items) 
       if (item.Text == comboBox1.SelectedItem.ToString()) listView1.Items.Remove(item); 
     } 
    } 

希望這有助於!

+0

感謝您的答覆,但我得到這個錯誤對象引用未設置爲對象的實例。 – suffix

+0

我現在編輯它,嘗試檢查它... – Ginka

+0

謝謝你是awsome – suffix