ComboBox绑定Dictionary做为数据源】的更多相关文章

http://www.cnblogs.com/refresh/archive/2012/07/14/2591503.html https://msdn.microsoft.com/zh-cn/library/system.windows.forms.bindingsource(v=vs.80).aspx ComboBox的DataSource的值可设置为 :实现 IList 接口的对象,如 DataSet 或 Array.默认为 空引用(在 Visual Basic 中为 Nothing). 但…
DropDownList绑定Dictionary泛型类 定义一个Dictionary泛型类 /// <summary>    /// 产品类型    /// </summary>    /// <returns></returns>    public Dictionary<string, string> productType()    {        Dictionary<string, string> d = new Dict…
转载:http://blog.sina.com.cn/s/blog_629e606f01014d4b.html ComboBox最经常使用的事件就是SelectedIndexChanged.但在将ComboBox绑定到某个数据源的过程中,会触发SelectedIndexChanged事件,而这个时候用户并没有选择内容,其SelectedValue也不是对应字段的值.那么时写在SelectedIndexChanged中的处理代码就会因为SelectedValue的内容不正确引发异常.一般网上找到的…
出现问题: 当多个ComboBox绑定同一个数据源后,只要更改其中一个的选择项时,其它的ComboBox也跟着改变了 解决办法: DataTable dt = new DataTable(); dt = Common.XmlToDatatable(mPath, "常用四至"); DataRow dr = dt.NewRow(); dr["四至名称"] = "";//添加空行 dt.Rows.InsertAt(dr, ); cmbDZ.DataSo…
1. 将集合数据绑定到ListBox和ComboBox控件,界面上显示某个属性的内容 //自定义了Person类(有Name,Age,Heigth等属性) List<Person> persons=new List<Person>(); persons.Add(,)); persons.Add(,)); persons.Add(,)); //ListBox控件实现 lb_PersonsList.DataSource=persons; //指定数据源 lb_PersonList.Di…
ComboBox绑定List时可能会错, public class Person { public string Name; public int Age; public int Heigth; } 调用如下 List<Person> persons = new List<Person>(); persons.Add(new Person() {Age =12,Name = "asd",Heigth = 123}); persons.Add(new Person…
DisplayMemberPath 是用来显示下拉列表的值 SelectedValuePath是用来取得选中项的值. ComboBox绑定类对象, 下拉列显示的值,与取到的值 string. Join的作用 输出结果是…
silverlight中 ComboBox绑定数据库,并获取当前选定值 在silverlight中 用combobox下拉菜单绑定数据库的方法和用DataGrid绑定数据库的方法类似. page.xaml.cs代码: //调用获取 企业联系人姓名 ServiceReference1.Class2 qyLXR = new Class2(); ServiceReference1.Service1Client obj_qyl = new Service1Client(); obj_qyl.qylxrC…
一般情况下我们会将 DataTable 或 DataView 绑定到 Combobox 控件上,这时候进行数据绑定是没有问题的,因为DataTable 和 DataView 都继承了 IList 接口.但是有些情况下我们需要将泛型的集合类当作数据源,这时候就会报 复杂的 DataBinding 接受 IList 或 IListSource 作为数据源 的错误.原因是这些类型没有继承上述的两个接口,所以要使用一个 BindingSource 类将数据源封装一下,BindingSource 类继承和…
第一种 最简洁的方法 Dictionary<string, string> list = new Dictionary<string, string> { {"this is i1", "001"}, {"this is i2", "002"} }; private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.AddRang…
程序功能: 使用ComboBox做级联,数据源为XML文件,适合小数据量呈现 程序代码: <Window x:Class="WpfApplication1.LayouTest" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:core=&…
实现: 一.绑定数据库 点击查询按钮,comboBox显示从数据库查到的某字段的一列数据 方法:在按钮的点击事件绑定数据库 private void button1_Click(object sender, EventArgs e) { using (SQLiteConnection con = new SQLiteConnection(Constants.DATA_SOURCE)) { con.Open(); using (SQLiteCommand cmd = new SQLiteComma…
在为 ComboBox 当定数据的时候,如果遇到界面显示需要用文本,而获取选定项的值时需要用数字,我们就很习惯使用 DataSource  来进行绑定. 例如以下代码: List<TextValue> tvList = new List<TextValue>(); ; i < ; i++) { tvList.Add(new TextValue(i.ToString(), i)); } ComboBox cmb = new ComboBox(); cmb.DataSource…
思路:给ComboBox控件设置它的ItemSource绑定到ViewModel中的某个列表上,该列表是某个实体类的集合(如List< Person >),而ComboBox列表要显示的是该实体类的某一属性(如person.Name). 大致步骤: 联网获取到这组数据的Json,然后反序列化为对应的List< 实体类 >列表. 由于只想要绑定这组实体类的Name属性,所以再准备一个List< string >集合,保存List< 实体类 >中的每一个对象的N…
问题] 在最近的项目中使用DataGrid的DataGridCheckBoxColumn绑定了后台TagModel类的IsSelected字段,数据源是TagModel类型的Dictionary,运行发现Checkbox不能正常勾选,提示错误:此视图不允许“EditItem”. [问题重现] 前台: <DataGridCheckBoxColumn Binding="{Binding IsSelected}" /> 后台: Dictionary<string, TagM…
1.DataTable绑定 用DataTable直接绑定,只需要设置DataSource.DisplayMember.ValueMember三个属性即可. this.cmbConsume.DataSource = dtSuperMarket; this.cmbConsume.DisplayMember = "Name"; this.cmbConsumet.ValueMember = "ID"; ; //选中第一项 在使用时使用如下方式,即可取得相应的ID和Name:…
C#中comboBox用代码绑定数据库中在某一列.用处:跟radioButton联系在一起,可以根据radioButton在选择而在comboBox显示出不同的值. private void radioButton1_Click(object sender, EventArgs e) { comboBox1.Items.Clear(); //清空ComBox string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydb.m…
将集合数据绑定到ListBox和ComboBox控件,界面上显示某个属性的内容 //... //自定义了Person类(有Name,Age,Heigth等属性) List<Person> persons=new List<Person>(); persons.Add(,)); persons.Add(,)); persons.Add(,)); //ListBox控件实现 lb_PersonsList.DataSource=persons; //指定数据源 lb_PersonList…
mboBox下拉菜单控件,在数据库内的ComboBox应用的表进行修改时,如果是用的普通方法,显示数据一个方法,添加数据一个方法 这样会导致程序后期维护难度增加,在这里使用数据绑定来让ComboBox数据实现根据数据库对应表数据显示,降低数据维护难度. 1.首先将要ComboBox所需要的表的数据全部查询出来 2.对查询获得的数据用实例化泛型集合List进行接收 3.设置需要显示的列[数据] 4.设置对数据库操作需要的列[数据] public Form3() //窗体打开自动执行的数据 { In…
Dictionary中的<string, CustomeType>CustomeType是一个集合,将其绑定生成一棵树,树的第一层节点是Dictionary的Key,第二层是CustomeType集合,所有代码用XAML实现. 代码如下: <TreeView Name="dictree" ItemsSource="{Binding}"> <TreeView.Resources> <HierarchicalDataTempla…
1.数据本地绑定 var card = [{ "value": "正常", "text": "正常" }, { "value": "挂失", "text": "挂失" }, {"value":"注销","text":"注销"}] $('#Numbers').datagr…
刚才遇到一个怪现象:同一个窗口,同一张表,通过第一个Combobox值的改变,动态绑定第二个Combobox,结果出现一个怪现象,第一个Combobox有的值改变第二个Combobox一切正常,有几个值就会引起第二个System.Data.DataRowView的问题,添加了DataSource = Nothing.改变了DisplayMember.ValueMember顺序都无济于事.郁闷了2个小时. 最后解决方法:定义一个临时DataTable,先给临时DataTable赋值,然后将临时Da…
前台端 <ComboBox HorizontalAlignment="Name="cmb_SSBM" DisplayMemberPath="NAME" SelectedValuePath="CODE" SelectedIndex="-1" / > 后台代码段 WJKCDataContext wjkc = new WJKCDataContext(); cmb_SSBM.ItemsSource = wjkc.…
最近感觉新的方法Binding comboBox用起来很好用. 记录一下: <ComboBox Grid.Row=" x:Name="cboFamilyName" DisplayMemberPath="DisplayName" SelectedValuePath="idRow" IsEditable="True" IsReadOnly="True" ItemsSource="{Bi…
使用这种方式始终绑定值有问题: cbxSchool.DataSource = schoolList; cbxSchool.DisplayMember = "school_name"; cbxSchool.ValueMember = "school_id"; 选择改变事件获取选中值:cbxSchool.SelectedValue 始终是对象,不是想要的id. 解决方法: if (schoolList != null && schoolList.Coun…
comboBoxPlanResult.DataSource =new BindingSource(o,null);comboBoxPlanResult.DisplayMember ="Key";comboBoxPlanResult.ValueMember ="Value"; DataGridView  类,ListBox等控件支持标准的   Windows   窗体数据绑定模型.这意味着数据源可以是实现下列接口之一的任何类型:   IList   接口,包括一维数组…
​以往咱们分享的操作步骤都稍微有些复杂,大家跟着步骤操作也有些二丈摸不着头脑,看来简单的操作步骤和功能概念还是有必要普及的,那今天就来说一点简单的入门操作知识,以Smartbi为例子,跟大家说说BI工具的关系数据源连接.关系数据源连接是指通过"数据库驱动程序"连接一个本地或远程的关系数据库. 第一步:找到操作入口 1.可以选择系统导航栏的 数据连接,或者选择系统快捷菜单 数据连接 ,如图: 2.在"数据连接"界面主菜单选择 关系数据库 下的关系数据源 ,如图: 第二…
this.ComboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; this.ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; this.ComboBox1.DropDownWidth = 400; this.ComboBox1.DropDownHeight = 400; string sql = " sql语句 "; DataTable dt = L…
xaml: <Window x:Class="WpfApplication1.Window5" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:String="clr-namespace:System;assembly=msco…
定义枚举 public enum UserLevel { Commmon = , Administrator, Developer } 方法一 private void Method1() { comboBox1.DataSource = System.Enum.GetNames(typeof(UserLevel)); comboBox1.SelectedIndex = comboBox1.FindString(UserLevel.Commmon.ToString()); } 方法二 priva…