具有动态数据源的DataGridViewComboBoxColumn [英] DataGridViewComboBoxColumn With Dynamic DataSource

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

问题描述



我有可编辑的DataGridView来填充订购的产品,所以我有一个DataGridViewComboBoxColumn和DataTable数据源,其中包含所有产品代码,我根据列的值更改了dataview的rowFilter.例如:

datagridview为空
组合产品代码为:
11
1212
1555

用户添加行并从组合框代码"1212"中选择.
当用户添加另一行时,我过滤了组合dataView以排除代码"1212",因此组合将具有:
组合产品代码为:
11
1555

我在datagridview的EditingControlShowing事件中进行此过滤.

我的问题是dataGridView对于整个列使用相同的comboBox Instace,因此在我过滤了其源之后,第一行的单元格文本更改为空字符串,导致第二行中的组合没有在其中选择的值第一行.

有什么解决方法吗?

非常感谢!

Hi,

I have editable DataGridView to fill ordered Products, so i have a DataGridViewComboBoxColumn with DataTable datasource that contain all products codes, i change the rowFilter of the dataview depending on values of the column. for exmple:

datagridview is empty
Combo product codes are :
11
1212
1555

the user added row and choosed from the combobox code "1212" .
when the user added anther row i filter the combo dataView to exclude the code "1212" so the combo will have :
Combo product codes are :
11
1555

I do this filtering In EditingControlShowing event of the datagridview.

My problem is that the dataGridView uses the same comboBox Instace for the whole column so after i filter its source the cell text of the first row change to empty string cause the combo in the second row doesn''t have the value that was choosen in the first row.

Is there any work around?

Thanks a lot!

推荐答案

在下拉列表选择索引已更改"事件中,从下拉列表中删除选定的项目.
就像这样,

In Dropdown selection index changed event, remove the selected item from the dropdown.
It would be something like this,

GridViewRow grdrow = ((DropDownList)sender).Parent.Parent as GridViewRow;
               DropDownList ddlProducts = (DropDownList)grd.Rows[grdrow.RowIndex].FindControl("YourDrpDown");
               ddlProducts.Items.Remove(ddlProducts.SelectedItem);


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

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