尝试了很多种方案,由于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. python多线程ssh爆破

    python多线程ssh爆破 Python 0x01.About 爆弱口令时候写的一个python小脚本,主要功能是实现使用字典多线程爆破ssh,支持ip表导入,字典数据导入. 主要使用到的是pyth ...

  2. cell自适应高度

    MyModel.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface MyModel : ...

  3. iOS开发之网络编程--4、NSURLSessionDataTask实现文件下载(离线断点续传下载) <进度值显示优化>

    前言:根据前篇<iOS开发之网络编程--2.NSURLSessionDownloadTask文件下载>或者<iOS开发之网络编程--3.NSURLSessionDataTask实现文 ...

  4. 如何在sublime text 3 上安装插件package control

    今天由于帮同事搞web方面的东西,于是又重新安装了sublime text 这款神器.发现官方网站都更新到sublime text3了,于是下载装了下,突然发现少了很重要的一个功能,竟然没有packa ...

  5. 在阿里云主机的Debian操作系统上安装Docker

    因为需要新搭建饭团网站,所以需要在阿里云的主机上跑数据库,java环境. 考虑到可扩展性和模块化,所以准备最近流行的docker技术.Docker -- 从入门到实践 阿里云主机1核1G,资源不多,所 ...

  6. 【重构】 利用 cos 组件实现jsp中上传附件

    利用JSP&Servlet重构项目 利用 cos 组件实现jsp中上传附件 fileUpload.jsp --> FileUploadController.java --> fil ...

  7. .bat脚本基本命令语法

    目录批处理的常见命令(未列举的命令还比较多,请查阅帮助信息)     1.REM 和 ::     2.ECHO 和 @     3.PAUSE     4.ERRORLEVEL     5.TITL ...

  8. Effective Java 76 Write readObject methods defensively

    Principle readObject method is effectively another public constructor, and it demands all of the sam ...

  9. Web Service中的几个重要术语

    WSDL:web service definition language 直译:WebService定义语言 1.对应一种该类型的文件.WSDL 2.定义了Web Service的服务器与客户端应用交 ...

  10. sublime生产力提升利器

    sublime 操作快捷键功能-生产力提升利器 Go to anything  ctrl+p 支持快速模糊匹配 查找替换  ctrl+h 多行游标(当只需查找/替换/选中部分相同内容时)有以下方式来产 ...