zoukankan      html  css  js  c++  java
  • 【原创】有关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[3].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 = -1, 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 == 1)
                            CurrentRowIndusrtySublist.SelectedIndex = 0;
                        else
                            CurrentRowIndusrtySublist.SelectedIndex = 1;
                        //if (_OldSubindustryId != 0)
                            //CurrentRowIndusrtySublist.SelectedItem = (from q in CurrentRowIndusrtySublist.Items where (q as System_IndustryCodes).ID == _OldSubindustryId select q).FirstOrDefault();//默认选择项-子行业
                    }, null);
                }
            }

    最终效果:

  • 相关阅读:
    Ping
    boost::python开发环境搭建
    mingw和libcurl
    ssh远程执行命令使用明文密码
    netty源码阅读之UnpooledByteBufAllocator
    Direct ByteBuffer学习
    clions的使用
    netty中的PlatformDependent
    STL之priority_queue(优先队列)
    c++线程调用python
  • 原文地址:https://www.cnblogs.com/x-poior/p/4897353.html
Copyright © 2011-2022 走看看