带有数据绑定的combox [英] combox with databound

查看:91
本文介绍了带有数据绑定的combox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用databound从数据库中获取值时,如何隐藏此组合中的(或使某些项目不可见).
当我尝试删除某些项目时,发生以下错误
设置DataSource属性时,无法修改项目集合.
最好的问候

when I used databound for get the value from database, how can I hide or (make some items invisable) from this combo.
when I tried to delete some items the following error occur
Items collection cannot be modified when the DataSource property is set.
best regards

推荐答案

首先根据当前ComboBox数据源创建一个DataTable:

first make a DataTable from current ComboBox DataSource:

DataTable dt =(DataTable) comboBox1.DataSource;



然后在DT中找到目标项目并将其从DT中删除.
然后再次为comboBox datasourse设置DT:



then find target item in DT and remove it from DT.
then set again DT for comboBox datasourse:

  DataTable dt = (DataTable)comboBox1.DataSource;
           
DataRow dr = dt.Rows.Find("TargetKey");
dt.Rows.Remove(dr);
           
comboBox1.DataSource = dt;


你好somur-ruteeb,

试试这个..

您没有将集合绑定到combobox数据源,而是为每行添加了项目到combobox.Itemscollection.这样,我们可以为组合框中的每一行使用不同的值.

谢谢

补充
Hello somur-ruteeb,

Try out this..

Instead of binding the the collection to the combobox datasource you''ve added items to combobox.Itemscollection for each row. This way we can have different values for each row in the combobox.

Thanks

Renish


这篇关于带有数据绑定的combox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆