【原创】有关Silverlight中“DataGrid中级联动态绑定父/子ComboBox ”的示例。
尝试了很多种方案,由于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 ”的示例。的更多相关文章
- WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选)
原文:WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选) 前台代码 <DataGrid.Columns> <DataGridCheckB ...
- 【原创】有关Silverlight中“DataGrid中单元格动态绑定ComboBox单击时数据项莫名被清除 ”的解决方案及思路。
今天上班遇到一个很古怪的问题,搞了半天愣是没找到原因.是这样的,在Datagrid中有绑定一个ComboBox列,其不包含在 model数据中,而是单独在LoadingRow事件中去 从数据库拿数据绑 ...
- Silverlight 中DataGrid中全选与非全选问题
问题:当点击全选时,全选所有的复选框,但是滚动屏幕时,却复选框就会取消选中 一.解决方法(将要展示的实体数据模型添加bool属性,在数据绑定时添加click时间,盘带选中的状态,就可以了) 1. xa ...
- Silverlight 查询DataGrid 中匹配项 ,后台改变选中行颜色
需求:根据关键字(参会人号码或名称)查找参会人,在datagird 中高亮显示 界面:我在界面上增加了一个文本框和按钮,进行查找操作 操作说明: 根据关键字进行搜索:输入关键字 点击查找,如果找到 以 ...
- esayUi中datagrid中json串为空时,显示上一次数据的解决方法
function initSearchProject(startDate,finishDate,flag) { $("#finishDate").val(finish ...
- jquery中datagrid中getSelected和getSelections的应用
http://blog.sina.com.cn/s/blog_8e50ede90101fff9.html 刚开始使用jquery的datagrid就知道如果要对特定的一行进行编辑,可以是 $('#on ...
- jeecg中datagrid中获取选定行的字段值
datagrid代码如下: <t:datagrid name="orderMainList" checkbox="true" pagination=&qu ...
- EasyUI 的DataGrid中DateTime的格式化问题
想必用过EasyUI的朋友们都应该会遇到这样的情况吧:(下图) 在EasyUI中DataGrid中如果要显示DateTime的时间时候,便会显示上图这样的格式,很明显,这里的格式不会是我们想要的,我们 ...
- silverlight中datagrid数据到处excel
首先新建一个DataGrdiExtensions类,代码为: public static class DataGridExtensions { /// <summary> /// 导出dg ...
随机推荐
- SQL 查询学生缺考情况
有三个表,如果学生缺考,那么在成绩表中就不存在这个学生的这门课程成绩的记录,写一段SQL语句,检索出每个学生缺考的科目.A 学生表(student)字段1 学生号(s_id)字段2 学生名(s_nam ...
- Static Cell-静态TableView
使用静态TableView有两个前提,1.要在Storyboard上 2.需要使用TableViewController PS:如果需要设置不同的cell的高度不同的话,还是需要使用tableVie ...
- NSEnumerator
NSEnumerator 基本理解 NSEnumerator是一个抽象类,它没有用来创建实例的公共接口.而NSArray,NSDictionary,NSSet可以通过相关方法返回一个实例 可以使用它的 ...
- 弃用的同步get和post请求
#import "ViewController.h" #import "Header.h" @interface ViewController () <N ...
- iOS NSDate、NSCalendar、NSDateComponents
时间解析(NSDate.NSCalendar.NSDateComponents): 1.使用NSCalendar和NSDateComponents解析日期,直接获取到年月日时分秒.获取到年月日时分秒其 ...
- ios 删除系统从相册压缩的视频
iOS的沙盒机制,应用只能访问自己应用目录下的文件.iOS不像android,没有SD卡概念,不能直接访问图像.视频等内容.iOS应用产生的内容,如图像.文件.缓存内容等都必须存储在自己的沙盒内.默认 ...
- (第五章)java面向对象之this的作用总结
this关键字总是指向调用该方法的对象. this可以代表任何对象,当this出现在某个方法体中时,它所代表的对象是不确定的,但它的类型是确定的,它所代表的对象只能是当前类的(在那个类中就是那个类), ...
- Atitit. 软件设计 模式 变量 方法 命名最佳实践 vp820 attilax总结命名表大全
Atitit. 软件设计 模式 变量 方法 命名最佳实践 vp820 attilax总结命名表大全 1. #====提升抽象层次1 2. #----使用通用单词1 3. #===使用术语..1 4. ...
- c#发送http请求
直接代码,自己备用 /** * @method:生成验证码 */ [JSONMethod] [Description ( "生成验证码" )] [DomTemplate ( )] ...
- Android增加v7 appcompat源码
1.File ---- Import---- Existing Android Code Into Workspace 2.选择 <sdk>/extras/android/support/ ...