尝试了很多种方案,由于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. Powershell Remove "Limited Access" - 金大昊(jindahao)

    对于有多级web获取getlist会报错:Exception calling “GetList” with “1” argument $SPWeb = Get-SPWeb -Identity http ...

  2. 强大的UML建模工具——StarUML

    用例图: usecase          生成时序图,协作图,活动图等            生成的时序图:           反向工程以及生成代码:          类图:           ...

  3. C++函数模板

    函数模板提供了一种函数行为,该函数行为可以用多种不同的类型进行调用,也就是说,函数模板代表一个函数家族,这些函数的元素是未定的,在使用的时候被参数化. 本文地址:http://www.cnblogs. ...

  4. Struts2(十)OGNL标签二与Struts2标签

    一.Struts2标签的优势 标签库简化了用户对标签的使用 结合OGNL使用,对于集合.对象的访问功能非常强大 提供可扩展的主题.模板支持.极大简化了视图页面的编写 不依赖任何表现层技术 Struts ...

  5. HTML5 -1- 简介

    在介绍HTML5之前我们应该先了解一下HTML5 我想从下面开始简单了解一下HTML5 什么是HTML5??? HTML5 即HTML 5.0 版本 正式制定时间是在2014年 遵循着移动先行(前四个 ...

  6. 网络开始---多线程---NSThread-02-线程状态(了解)(三)

    #import "HMViewController.h" @interface HMViewController () @property (nonatomic, strong) ...

  7. Android UI之下拉刷新上拉刷新实现

    在实际开发中我们经常要用到上拉刷新和下拉刷新,因此今天我写了一个上拉和下拉刷新的demo,有一个自定义的下拉刷新控件 只需要在布局文件中直接引用就可以使用,非常方便,非常使用,以下是源代码: 自定义的 ...

  8. 多线程基础(五)NSThread线程通信

    5.多线程基础 线程间通信   什么叫线程间通信 在一个进程中,线程往往不是孤立存在的,多个线程之间需要经常进行通信   线程间通信的体现 1个线程传递数据给另一个线程 在1个线程中执行完特定任务后, ...

  9. UVa 109 - SCUD Busters(凸包计算)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  10. SQLServer中char与varchar的区别

    今天写一个项目的用户登录部分 刚开始做,所以是数据库和程序一起写 一开始没注意 在定义表T_Person时吧PerID和PerPwd的类型设定都是char(20) 并且写入了几个数据,诸如 id:01 ...