2013-03-10 73 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