我做的是WinForm C/S程序
我的窗体上有个ComboBox控件 我是通过后台代码绑定的数据
现在我想实现这样一个效果 就是 如果我随便输入一个值 然后跟ComboBox里面的Items的值 进行匹配 然后又相同的 就使ComboBox里面的这个值 为默认选中项 我试了好多种方法 但是都没实现 希望那位达人 能够帮忙解决下这个问题 很急的我
我的窗体上有个ComboBox控件 我是通过后台代码绑定的数据
现在我想实现这样一个效果 就是 如果我随便输入一个值 然后跟ComboBox里面的Items的值 进行匹配 然后又相同的 就使ComboBox里面的这个值 为默认选中项 我试了好多种方法 但是都没实现 希望那位达人 能够帮忙解决下这个问题 很急的我
解决方案 »
- 请问如何修改文本文件中的某一行?
- arraylist:集合已修改,可能无法执行枚举的错误
- 在girdview实现删除操作,这些个语法有错误吗?
- .NET三层架构中如何实现图片验证码?以及验证
- 出了点小问题,三处红波浪线.错误 1 应输入 class、delegate、enum、interface
- 请教:将“同一个应用程序分多个进程同时执行”和“多个相同应用程序(名称不同而已)分单一进程”同时执行,那一种性能要好些。。
- .NET环境下自动内存管理概念的一些疑问
- 查找目錄下指定文件
- 100分请教这个问题(不够在加)
- 路径带空格和中文,加引号也无效怎么解决啊
- 从网上下载源码后进行分析的进度显示问题
- sql2005 vs 2005数据库连接问题
{
for (int i = 0; i < comboBox1.Items.Count; i++)
{
if (comboBox1.Items[i].ToString() == textBox1.Text)
{
comboBox1.SelectedIndex = i;
return;
}
}
}
{
this.lbl_ID.Text=this.DgdvUser.Rows[e.RowIndex].Cells[0].Value.ToString();
string Group = this.DgdvUser.Rows[e.RowIndex].Cells[1].Value.ToString();
for (int i = 0; i < Cbo_Group.Items.Count; i++)
{
if (Cbo_Group.Items[i].ToString() == Group)
{
this.Cbo_Group.SelectedIndex = i;
string kl=Group;
}
}
}你看我写的 这是我测试的时候写的
{
this.lbl_ID.Text=this.DgdvUser.Rows[e.RowIndex].Cells[0].Value.ToString();
string Group = this.DgdvUser.Rows[e.RowIndex].Cells[1].Value.ToString();
for (int i = 0; i < Cbo_Group.Items.Count; i++)
{
if (Cbo_Group.Items[i].ToString() == Group)
{
this.Cbo_Group.SelectedIndex = i;
string kl=Group;
break; // 加上这行代码,如果还不行,请使用MessageBox.Show(Group); 查看Group的值
}
}
}
使用MessageBox.Show(comboBox1.Items[i].ToString().Length.ToString() + " " + Group.Length.ToString())
查看他们的长度是否一样
Cbo_Group的每一项都比较过了吗?长度不一样?
用SelectedValue不行吗
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace CStest
{
class ListSort
{
public Dictionary<string, string> SortByID(AreaList[] arealist, string strFind)
{
Dictionary<string, string> Dic = new Dictionary<string, string>(); ArrayList al = new ArrayList();
for (int i = 0; i < arealist.Length; i++)
{
al.Add(arealist[i].ID);
}
al.Sort();
foreach (object s in al)
{
for (int i = 0; i < arealist.Length; i++)
{
if (s.ToString().Contains(strFind) && s.ToString().CompareTo(strFind) >= 0 && s.ToString() == arealist[i].ID)
{
Dic.Add(arealist[i].ID, arealist[i].Name);
break;
}
}
}
return Dic;
} public Dictionary<string, string> SortByName(AreaList[] arealist, string strFind)
{
Dictionary<string, string> Dic = new Dictionary<string, string>();
string[] tempList = new string[arealist.Length];
ArrayList al = new ArrayList();
for (int i = 0; i < arealist.Length; i++)
{
al.Add(arealist[i].Name);
}
al.Sort();
foreach (object s in al)
{
for (int i = 0; i < arealist.Length; i++)
{
if (s.ToString().Contains(strFind) && s.ToString().CompareTo(strFind) >= 0 && arealist[i].Name == s.ToString())
{
Dic.Add(arealist[i].Name, arealist[i].ID);
break;
}
}
}
return Dic;
}
} public struct AreaList
{
public string ID;
public string Name;
} public unsafe struct AreaListTemp
{
public int ID;
public char* Name;
} unsafe class ListSortTemp
{
}
} private void FillListView(AreaList[] arealist)
{
listBox1.Items.Clear();
Regex r = new Regex("[^\x00-\xff]");
if (r.IsMatch(Form1.KeyWords))
{
Dictionary<string, string> Dic = ls.SortByName(arealist, Form1.KeyWords);
if (Dic.Count < 1)
{
Hide();
return;
}
else
{
NameList = new string[Dic.Count];
Show();
}
int i = 0;
foreach (KeyValuePair<string, string> kv in Dic)
{
NameList[i] = kv.Key;
listBox1.Items.Add(kv.Key + "(" + kv.Value + ")");
i++;
}
listBox1.SelectedIndex = 0;
}
else
{
Dictionary<string, string> Dic = ls.SortByID(arealist, Form1.KeyWords);
if (Dic.Count < 1)
{
Hide();
return;
}
else
{
NameList = new string[Dic.Count];
Show();
}
int i = 0;
foreach (KeyValuePair<string, string> kv in Dic)
{
NameList[i] = kv.Value;
listBox1.Items.Add(kv.Key + "(" + kv.Value + ")");
i++;
}
listBox1.SelectedIndex = 0;
}
this.Invalidate();
//if (listBox1.Items.Count < 1)
//{
// IsShow = false;
//}
}现在就是有一个问题,数据上1000就感觉跑不动了,而c++做的类似的控件数量可以达到1000W还感觉不到慢,
我要的效果是这样的:我的ComboBox通过后台绑定数据 然后我通过其他地方获得了一个值 然后吧这个值跟我ComboBox里面的集合进行匹配如果存在相同的值 那就把ComboBox里的这个值给设置成选中状态 按我原来的想法是 循环遍历ComboBox里面的Items来进行匹配值但是我直接试了好多种方法 就是没实现这个效果
foreach (object bj in comboBox1.Items)
{
DataRowView dv =(DataRowView) bj;
comboBox1.SelectedItem = dv;
string uid=dv.Row["userid"].ToString();
if ( uid== aa)
{
comboBox1.SelectedItem = bj;
break;
}
}