尝试了很多种方案,由于Datagrid动态生成的每行父子comboBox的Name的不确定性,给父ComboBox绑定事件中获取 子ComboBox很难根据Name获取到。

花了不少时间和公司同事商讨,最终方案如下:

注:父子combobox分别代表: 主行业/子行业

  private void CurrentRowIndusrtylist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox combobox = sender as ComboBox;
//获取另一个conbox控件
CurrentRowIndusrtylist = (sender as ComboBox);
if (CurrentRowIndusrtylist != null)
{
DataGridCell dg = (DataGridCell)(CurrentRowIndusrtylist.Parent);//关键用法
if (DataGridRow.GetRowContainingElement(dg) != null)
{
CurrentRowIndusrtySublist = this.dataGrid9.Columns[].GetCellContent(DataGridRow.GetRowContainingElement(dg)) as ComboBox;//关键用法
if (CurrentRowIndusrtySublist != null)
BindSubIndusrtyCodes();//动态去绑定子combobox
}
}
} private void BindSubIndusrtyCodes()
{
if (CurrentRowIndusrtylist.SelectedItem != null)
{
var unitIndusrtyItem = CurrentRowIndusrtylist.SelectedItem as System_IndustryCodes;
_db.Load(_db.GetIndustryCodesQuery(), op =>
{
CurrentRowIndusrtySublist.Items.Clear();
CurrentRowIndusrtySublist.Items.Add(new System_IndustryCodes { ID = -, IndustryCodes = "--请选择子行业--" });
IEnumerable<System_IndustryCodes> tempsubList = op.Entities.Where(q => q.ParentCodeID == unitIndusrtyItem.ID);
foreach (var temp in tempsubList)
{
if (temp == null)
return;
CurrentRowIndusrtySublist.Items.Add(new System_IndustryCodes { ID = temp.ID, IndustryCodes = temp.IndustryCodes });
}
CurrentRowIndusrtySublist.DisplayMemberPath = "IndustryCodes";
CurrentRowIndusrtySublist.SelectedValuePath = "ID";
CurrentRowIndusrtySublist.UpdateLayout();
if (CurrentRowIndusrtySublist.Items.Count == )
CurrentRowIndusrtySublist.SelectedIndex = ;
else
CurrentRowIndusrtySublist.SelectedIndex = ;
//if (_OldSubindustryId != 0)
//CurrentRowIndusrtySublist.SelectedItem = (from q in CurrentRowIndusrtySublist.Items where (q as System_IndustryCodes).ID == _OldSubindustryId select q).FirstOrDefault();//默认选择项-子行业
}, null);
}
}

最终效果:

【原创】有关Silverlight中“DataGrid中级联动态绑定父/子ComboBox ”的示例。的更多相关文章

  1. WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选)

    原文:WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选) 前台代码 <DataGrid.Columns> <DataGridCheckB ...

  2. 【原创】有关Silverlight中“DataGrid中单元格动态绑定ComboBox单击时数据项莫名被清除 ”的解决方案及思路。

    今天上班遇到一个很古怪的问题,搞了半天愣是没找到原因.是这样的,在Datagrid中有绑定一个ComboBox列,其不包含在 model数据中,而是单独在LoadingRow事件中去 从数据库拿数据绑 ...

  3. Silverlight 中DataGrid中全选与非全选问题

    问题:当点击全选时,全选所有的复选框,但是滚动屏幕时,却复选框就会取消选中 一.解决方法(将要展示的实体数据模型添加bool属性,在数据绑定时添加click时间,盘带选中的状态,就可以了) 1. xa ...

  4. Silverlight 查询DataGrid 中匹配项 ,后台改变选中行颜色

    需求:根据关键字(参会人号码或名称)查找参会人,在datagird 中高亮显示 界面:我在界面上增加了一个文本框和按钮,进行查找操作 操作说明: 根据关键字进行搜索:输入关键字 点击查找,如果找到 以 ...

  5. esayUi中datagrid中json串为空时,显示上一次数据的解决方法

    function initSearchProject(startDate,finishDate,flag) {        $("#finishDate").val(finish ...

  6. jquery中datagrid中getSelected和getSelections的应用

    http://blog.sina.com.cn/s/blog_8e50ede90101fff9.html 刚开始使用jquery的datagrid就知道如果要对特定的一行进行编辑,可以是 $('#on ...

  7. jeecg中datagrid中获取选定行的字段值

    datagrid代码如下: <t:datagrid name="orderMainList" checkbox="true" pagination=&qu ...

  8. EasyUI 的DataGrid中DateTime的格式化问题

    想必用过EasyUI的朋友们都应该会遇到这样的情况吧:(下图) 在EasyUI中DataGrid中如果要显示DateTime的时间时候,便会显示上图这样的格式,很明显,这里的格式不会是我们想要的,我们 ...

  9. silverlight中datagrid数据到处excel

    首先新建一个DataGrdiExtensions类,代码为: public static class DataGridExtensions { /// <summary> /// 导出dg ...

随机推荐

  1. IOS xib在tableview上的简单应用(通过xib自定义cell)

    UITableView是一种常用的UI控件,在实际开发中,由于原生api的局限,自定义UITableViewCell十分重要,自定义cell可以通过代码,也可以通过xib. 这篇随笔介绍的是通过xib ...

  2. System.Data.Entity 无法引用的问题

    最近刚学MVC,跟着网上的博客学习,发现代码中有这样一句: using System.Data; using System.Data.Entity; 我项目引用的时候,也引用了System.Data. ...

  3. SAM4E单片机之旅——19、CAN间通信

    CAN协议具有良好的可靠性,在工业中应用广泛.这次就先熟悉CAN的基本功能. 开发板有两个CAN,每个CAN有8个信箱.这次内容是从CAN0的信箱0发送数据到CAN1的信箱0. 除本次使用的功能外,C ...

  4. MySQL数据库初识(二)

    8. 向数据表中插入数据记录(INSERT): 向数据表中插入数据记录有两种方法: 基本语法1:INSERT INTO 数据表 (字段名1,字段名2,字段名3……字段名n) VALUES (数据值1, ...

  5. 单点登录系统(SSO)之CAS(中央认证服务)

    SSO(Single Sign On)单点登录系统,是在多个系统中值要求只要登录一次,就可以用已登录的身份访问多个系统,去掉了每次访问不同的系统都要重新登录的弊端. CAS(中央/集中认证服务):Th ...

  6. nginx服务器中的安全配置

    一.关闭SELinux 安全增强型Linux(SELinux)的是一个Linux内核的功能,它提供支持访问控制的安全政策保护机制. 但是,SELinux带来的附加安全性和使用复杂性上不成比例,性价比不 ...

  7. 教你怎样写自定义IP地址算法

    通过IP地址可以看到算法规律,写成自定义IP地址,也可以把IP地址转为自定格式的IP地址.也可以用于加密一些明文数字.起始次方可自定义(以1次方和0次方为例) a.以下写正反算法(以1次方为最小单位) ...

  8. 软件测试作业3--Junit、hamcrest、eclemmat的安装和使用

    1.   how to install junit, hamcrest and eclemma? 首先下载下来Junit和Hamcrest的jar包,然后新建项目的时候将这两个jar包导入到工程里面就 ...

  9. A python tool to static sim.log duration time

    When working ALU IMS Patch team, we need to static the SU duration to add it to the patch report, th ...

  10. NOIP2008普及组传球游戏(动态规划)——yhx

    题目描述 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏. 游戏规则是这样的:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个同 ...