已修改此枚举器绑定的列表。只有在列表不更改时才能使用枚举器。 [英] List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.
本文介绍了已修改此枚举器绑定的列表。只有在列表不更改时才能使用枚举器。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在列表框中找到值并根据文本框值突出显示但是我收到此错误。我用Google搜索但未能找到我的答案。帮助....
谢谢..
加载列表框中的值
i trying to find values in listbox and highlight that according to textbox value but i am getting this error. I googled but failed to find my answer pls. Help....
Thank You..
to load values in listbox
private void FilterListBox_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("Data Source=SRISTI;Initial Catalog=Anjanee;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("select UserName from User_Name", cn);
DataSet ds = new DataSet();
da.Fill(ds, "ABC");
int count = ds.Tables[0].Rows.Count;
for (int i = 0; i < count; i++)
{
listBox1.Items.Add(ds.Tables[0].Rows[i]["UserName"].ToString());
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
foreach (string s in listBox1.Items)
{
if (s.StartsWith(textBox1.Text) == true)
{
listBox1.SelectedItem = s;
}
}
}
推荐答案
根据我的理解,你正在尝试做Autocomeplete窗口应用中的扩展器。
通过以下链接查看示例程序
http://www.mstecharticles.com/2010/12/auto-complete-text-box.html [ ^ ]
谢谢
--RA
As per my understand you are trying to do the Autocomeplete extender in window application.
Go through the below link for sample program
http://www.mstecharticles.com/2010/12/auto-complete-text-box.html[^]
Thanks
--RA
您可能会改变:
You might change from:
Quote:
foreach(listBox1.Items中的字符串s)
{
if(s.StartsWith(textBox1.Text)== true)
{
listBox1.SelectedItem = s;
}
}
foreach (string s in listBox1.Items)
{
if (s.StartsWith(textBox1.Text) == true)
{
listBox1.SelectedItem = s;
}
}
to
to
for(int i=0; i<listbox1.items;> {
if (listBox1.items[i].StartsWith(textBox1.Text) == true)
{
listBox1.SelectedIndex = i;
}
}
从MSDN试试这个例子。
http://msdn.microsoft.com/en- us / library / system.windows.forms.listbox.setselected.aspx [ ^ ]
希望这有帮助
Try this example from MSDN.
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.setselected.aspx[^]
Hope this helps
这篇关于已修改此枚举器绑定的列表。只有在列表不更改时才能使用枚举器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文