2013-03-10 23 views
2

我做了一個完整的INTERNET瀏覽器。我做了很多選擇,書籤創建了一個問題。假設我通過點擊記事本文件中的新值來獲得一個值,根據我的想法完成此操作。一個問題再次面臨着我,每次點擊都會得到重複的價值。如何避免重複數據請指導我。 我的編碼部分是: -如何Combobox通過鼠標點擊記事本(運行時)獲取數據?

private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) 
{ 
    int kkk = comboBox1.Items.Count; 

    string path = File.ReadAllText("F:\\kmm.txt"); 
    string[] y = path.Split('\n'); 
    foreach (string kk in y) 
    { 
     comboBox1.Items.Add(kk); 
    } 
    // comboBox1.Items.Clear(); 
    string km = comboBox1.SelectedItem.ToString(); 
    wb.Navigate(km); 
} 

抽點組合框:: enter image description here

+0

上的添加,您可以加載現有條目的列表。然後,如果(!(List.Contains(newEntry))){AddEntry(newEntry)};它的僞造,但應該做的伎倆。 – 2013-03-10 17:35:58

+0

@AthomSfere,但先生我問在組合框中添加運行時間數據....我有很多嘗試,幫我關於我的問題 – 2013-03-10 18:18:50

+0

我在等待正確的答案 – 2013-03-10 18:20:01

回答

0

每個ComboBox Selection Index改變時,項目從F:\kmm.txt加載。

你申請一個非常錯誤的邏輯加載項ComboBox

一個更好的辦法是在ComboBox只有一次加載事件的項目。

但是如果您想在comboBox1_SelectedIndexChanged_1事件中將項目添加到組合框中,您需要清除comboBox1中的項目。

試試這個方法:

private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) 
{ 
    int kkk = comboBox1.Items.Count; 

    string path = File.ReadAllText("F:\\kmm.txt"); 
    string[] y = path.Split('\n'); 

    // clear all existing items first 
    comboBox1.Items.Clear(); 

    foreach (string kk in y) 
    { 
     comboBox1.Items.Add(kk); 
    } 
    // comboBox1.Items.Clear(); 
    string km = comboBox1.SelectedItem.ToString(); 
    wb.Navigate(km); 
} 
+0

,但先生,我想添加我的點擊..假設我的資源管理器正在運行狀態,我添加一個書籤,然後檢查出我添加。 – 2013-03-10 17:47:18

+0

@ j.s.banger - 按照示例代碼! – 2013-03-10 17:48:12

+0

我嘗試你的編碼部分,但不能添加運行時間? – 2013-03-10 17:53:34

相關問題