c# – 如何将新项添加到绑定到实体的组合框?
发布时间:2020-12-15 21:24:17 所属栏目:百科 来源:网络整理
导读:由C#生成的设计类: // // usepurposeComboBox // this.usepurposeComboBox.DataSource = this.usepurposeBindingSource; this.usepurposeComboBox.DisplayMember = "Name"; this.usepurposeComboBox.FormattingEnabled = true; this.usepurposeComboBox.Loc
由C#生成的设计类:
// // usepurposeComboBox // this.usepurposeComboBox.DataSource = this.usepurposeBindingSource; this.usepurposeComboBox.DisplayMember = "Name"; this.usepurposeComboBox.FormattingEnabled = true; this.usepurposeComboBox.Location = new System.Drawing.Point(277,53); this.usepurposeComboBox.Name = "usepurposeComboBox"; this.usepurposeComboBox.Size = new System.Drawing.Size(218,21); this.usepurposeComboBox.TabIndex = 4; this.usepurposeComboBox.ValueMember = "id"; // // usepurposeBindingSource // this.usepurposeBindingSource.DataSource = typeof(mydatabaseEntities.usepurpose); 然后我将BindingSource(usepurposeBindingSource)绑定到实体: usepurposeBindingSource.DataSource = mydatabaseEntities.usepurposes; 并且我无法向usepurposeComboBox添加新行,因为它已被绑定.有解决方法吗? 解决方法
最简单的方法是在dataTable中添加一个新行,然后将你的comboBox绑定到它,如下所示:
公司comps = new Company(); //pupulate dataTable with data DataTable DT = comps.getCompaniesList(); //create a new row DataRow DR = DT.NewRow(); DR["c_ID"] = 0; DR["name"] = "Add new Company"; DR["country"] = "IR"; //add new row to data table DT.Rows.Add(DR); //Binding DataTable to cxbxCompany cxbxCompany.DataSource = DT; cxbxCompany.DisplayMember = "name"; cxbxCompany.ValueMember = "c_ID"; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails-3 – 强制在Rails中的HTML转义3
- 动态标绘演示系统1.2.1(for ArcGIS Flex)
- c# – 使用GetManifestResourceStream找不到嵌入式资源
- Oracle统计每个公司每年的员工信息——另类“两次分组”
- TRACE32 调试技巧
- Flex4 IBM ILOG OrgChart破解
- 正则表达式 – 如何在Visual Studio或SSMS“查找和替换”中
- c – 从xlC的模板功能问题的静态函数查找
- objective-c – 在xcode中使用try catch块在真实设备上显示
- objective-c – 后退按钮不会出现在推送的UIViewController