三维图怎么看-dnf安全模式解除不了
2023年3月31日发(作者:nero刻录软件破解版)
C#将Dictionary,StringDictionary等集合数据绑定到如comboB。。。
⼀般在使⽤C#提供的如combobx控件绑定数据源时都是直接绑定数据库⾥的数据的(DataTable,DataSet等)
最近在⼀个项⽬⾥需要使⽤combobox绑定类似“状态的”数据源,该字段⾥的数据最不可变,所以不需要从数据库⾥获取数据
由于字段只需要健值没有其他信息所以使⽤Dictionary是最合适不过了,但如何将集合⾥的数据绑定并再获取集合⾥的健值呢?
在google搜索⼀番并找到解决⽅案:
nary
("","百度");
("","⾕歌");
("","腾讯");
//绑定数据
urce=newBindingSource(dict,null);
ember="Key";//⽂本对应的值
yMember="Value";//显⽰的⽂本
//绑定选择事件
edIndexChanged+=newEventHandler(comboBox1_SelectedIndexChanged);
//专门存储字符串健值的集合类
//健值都是string类型
Dictionarysd=Dictionary();
("","淘宝");
("","天猫");
("","京东");
urce=newBindingSource(sd,null);
ember="Key";
yMember="Value";
edIndexChanged+=newEventHandler(comboBox2_SelectedIndexChanged);
完整代码:
/******************************************************************
*创建⼈:黄愿
*创建时间:2014-9-911:34:39
*说明:C#将Dictionary,StringDictionary等集合数据绑定到如comboBox等控件数据源中
*Email:huangyuan413026@
*******************************************************************/
usingSystem;
;
namespaceHTL
{
publicpartialclassBindDictionaryToDatasource:Form
{
publicBindDictionaryToDatasource()
{
InitializeComponent();
}
privatevoidBindDictionaryToDatasource_Load(objectsender,EventArgse)
{
nary
("","百度");
("","⾕歌");
("","腾讯");
//绑定数据
urce=newBindingSource(dict,null);
ember="Key";//⽂本对应的值
yMember="Value";//显⽰的⽂本
//绑定选择事件
edIndexChanged+=newEventHandler(comboBox1_SelectedIndexChanged);
//专门存储字符串健值的集合类
//健值都是string类型
Dictionarysd=Dictionary();
("","淘宝");
("","天猫");
("","京东");
urce=newBindingSource(sd,null);
ember="Key";
yMember="Value";
edIndexChanged+=newEventHandler(comboBox2_SelectedIndexChanged);
}
privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)
{
("comboBox1信息如下:rn索引:"+edIndex+",值SelectedValue:"+edValue+",⽂本Text:"++",SelectedItem:"+ng());
}
privatevoidcomboBox2_SelectedIndexChanged(objectsender,EventArgse)
{
("comboBox2信息如下:rn索引:"+edIndex+",值SelectedValue:"+edValue+",⽂本Text:"++",SelectedItem:"+ng());
}
}
}
ViewCode
设计代码:
namespaceHTL
{
partialclassBindDictionaryToDatasource
{
///
///Requireddesignervariable.
///
inercomponents=null;
///
///Cleanupanyresourcesbeingused.
///
///
protectedoverridevoidDispose(booldisposing)
{
if(disposing&&(components!=null))
{
e();
}
e(disposing);
}
#regionWindowsFormDesignergeneratedcode
///
///RequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///
privatevoidInitializeComponent()
{
ox1=ox();
ox2=ox();
dLayout();
//
//comboBox1
//
tingEnabled=true;
on=(107,69);
="comboBox1";
=(121,20);
ex=0;
//
//comboBox2
//
tingEnabled=true;
on=(107,127);
="comboBox2";
=(121,20);
ex=1;
//
//BindDictionaryToDatasource
//
aleDimensions=(6F,12F);
aleMode=;
Size=(292,273);
(ox2);
(ox1);
="BindDictionaryToDatasource";
="BindDictionaryToDatasource";
+=andler(ctionaryToDatasource_Load);
Layout(false);
}
#endregion
oxcomboBox1;
oxcomboBox2;
}
}
ViewCode
参考:
更多推荐
selectedindexchanged
发布评论