尝试了很多种方案,由于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. FileInputStream类

    FileInputStream和FileOutPutStream类都是用来操作磁盘文件的.如果用户对文件读取需求比较简单,则可以使用FileInputStream类,该类继承InputStream类 ...

  2. 【读书笔记】iOS-GCD-网络编程要不要使用GCD

    一,网络编程强烈推荐使用异步API. 二,对于网络编程可以断言“线程是魔鬼”.如果在网络编程中使用线程,就很可能会产生大量使用线程的倾向,会引发很多问题.例如每个连接都使用线程,很快就会用尽线程栈内存 ...

  3. UITabBarController的创建等基本方法

    #import "AppDelegate.h" @interface AppDelegate () <UITabBarControllerDelegate> @end ...

  4. Charles使用详情

    Charles各版本下载: Charles for Windows 32 bit Charles for Windows 64 bit Charles for linux Charles for Ma ...

  5. oracle 表空间使用情况

    --表空间使用情况 SELECT a.tablespace_name "表空间名", round(total/1024/1024,2) "表空间大小", rou ...

  6. C语言-06-复杂数据类型

    一.数组 1> 数组的定义和初始化 定义 ① 数组定义了同种类型数据的集合 ② 定义数组时,数组必须有固定的长度 初始化 ① 如果在定义数组时,初始化数组,数组元素的个数必须是常量 ② 如果不在 ...

  7. 关于ajax请求数据后,数据本身的js失效的一些想法

    今天遇到一个头疼的问题.我做一个左右翻页效果(客户要求能够无限翻页),所以只能动态请求数据,进行局部刷新操作. 这时候问题就出来了,当我请求翻页的时候,数据通过js填充到div里面,但这些数据,自身带 ...

  8. nodeJS创建工程

    转http://blog.csdn.net/i348018533/article/details/47258449 设置镜像地址 1.通过config命令 npm config set registr ...

  9. 关于JAVA中的static方法、并发问题以及JAVA运行时内存模型

    一.前言 最近在工作上用到了一个静态方法,跟同事交流的时候,被一个问题给问倒了,只怪基础不扎实... 问题大致是这样的,“在多线程环境下,静态方法中的局部变量会不会被其它线程给污染掉?”: 我当时的想 ...

  10. 获取微信openID 的步骤

    获取微信openid的步骤:1.进入-->判断openID是否为空: 空-->$url=urlencode("http://xxx/xxx.php");//回调链接 $ ...