条件绑定(如果条件为真,则datagridComboBox中的Dsiplay项) [英] Conditional Binding (Dsiplay items in datagridComboBox if a condition goes true)

查看:89
本文介绍了条件绑定(如果条件为真,则datagridComboBox中的Dsiplay项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个包含两列的数据表,第一列称为Column1(类型为字符串),第二列称为Column2(类型为Boolean),出于某种原因,我将此表限制为数据网格组合框列",我想显示该列.如果列2的值为true,则在数据网格组合框中的column1;如果值为false,则不显示它
有没有办法在XML或后面的代码中做到这一点,
谢谢Advanced

hi every body ,
i have a Data table Contains Two columns the First One Called Column1(of type string) , and the Second one called Column2(of type Boolean) , i bounded this table to Data Grid Combo Box Column , for some reasons i want to display the column1 in the data grid combo box column if the value of the column 2 is true and not display it if the value is false
is there a way o do that in XML , or code behind ,
thanks in advanced

推荐答案

您最好的选择是拥有一个单独的集合,您可以使用LinQ填充该集合,该集合存储数据表的所有正列,然后进行绑定此单独集合的组合框列.

希望这对您有帮助
Your best bet would be to have a separate collection which you can populate using LinQ, that stores all the positive columns of your datatable, and then bind the combo box column to this separate collection.

Hope this helps


您可以通过使用datagrid的OnItemDataBound事件在后面的代码中进行操作.


触发此事件后,数据将绑定到数据网格.因此,将列2的值获取为
You can do it in code behind by using OnItemDataBound Event of datagrid.


The data is bounded to the datagrid upon firing this event.So, get the column 2 value as
<pre lang="c#">
protected void OnItemDataBound(object sender,DataGridItemEventArgs e)
if(e.Item.Cells[1].Text==1)//column2 value is either 0 or 1 whether true or false
{
//Do Some Action To remove data from Column 1 such as 
   //e.Item.Cells[0].Text=String.Empty;
}


这篇关于条件绑定(如果条件为真,则datagridComboBox中的Dsiplay项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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