复选框列表自定义控件 [英] CheckBox List Custom Control

查看:89
本文介绍了复选框列表自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有趣的场景,我设法开始工作,但是我想把它扔掉,看看是否有更好的或正式的"工作机会.我应该做的事情.我想理想地创建一个通用的自定义控件来处理此问题,但是现在 我要填充包含复选框列表的自定义控件,该控件列表绑定到写在屏幕后面的代码,并且实现每个CheckBox列表充其量是繁琐的.  

基本要求:

- 创建复选框列表作为自定义控件
-复选框"列表中的选项绑定到最终用户可更新的选项列表(下面的选项实体)
- 已检查的项目需要保存和检索,并与报告"相关联. (下面的报告选项"实体)
- 需要使用应用程序数据"实体(因此,除非有人可以解释如何使用应用程序数据",否则数据库中没有Views,也没有自定义WCF RIA服务)

应用数据:

报告[1]-> [N]个报告选项[N]-> [1]选项

当前,为此创建屏幕时,报告选项显示为数据网格,其中包含选项实体中每个项目的下拉选项.  可以,但是我们正在尝试为UX创建一个类似表单的体验,并创建一个CheckBox列表 与一堆带有数据网格"的选项卡相比,对于最终用户而言,它更为明显和可用.  

从概念上讲,我要完成的工作是将所有Option实体(与1个Report的Report Option实体一起)加入OUTER JOIN,并将结果传递到我的自定义控件中,这样我就可以显示所有可用的Pptions,而仅检查那些已经保存的 在报告选项"实体中.  

 

在我的报告详细信息"屏幕中,这是我目前在后面的代码中将两个实体集组合成CheckBox List可以使用的东西的地方:

 

  partial void ReportDetail_Activated()
  {
   var proxy = this.FindControl("CheckBoxList");
   proxy.ControlAvailable += OnControlAvailable;
  }

  private void OnControlAvailable(object sender, ControlAvailableEventArgs e)
  {
   this.Details.Dispatcher.BeginInvoke(() =>
   {
    EntitySet<Options> options = this.DataWorkspace.ApplicationData.Options;
    ObservableCollection<ISelectableItem> checkboxListItems = new ObservableCollection<ISelectableItem>();
    
    foreach (Option o in options)
    {
     checkboxListItems.Add(new SelectableItem<Option>(false, o.Description, o));
    }

    foreach (ReportOption j in this.ReportOption)
    {
     foreach (SelectableItem<Option> cb in checkboxListItems)
     {
      if (cb.Text == j.Option.Description)
      {
       cb.IsSelected = true;
      }
     }
    }

    Dispatchers.Main.BeginInvoke(() =>
    {
     _checkboxListItems.Clear();

     foreach (ISelectableItem i in checkboxListItems)
     {
      _checkboxListItems.Add(i);
     }

     CheckboxList cbl = e.Control as CheckboxList;
     cbl.DataContext = _checkboxListItems;

     _isInitalized = true;
    });
   });
  }

解决方案

你好RyanCain,

           我是电灯开关的新手.我是asp.net开发人员,目前跳到电灯开关应用程序.

           我需要在电灯开关中实现复选框列表"控件,并在最终保存单击时从复选框列表"中获取选中的复选框值.还使用以下方式绑定此复选框列表控件 存储过程.

           请帮助我,我一直在偷看,但是.........

           在我的自定义控件中,在system.widows中找不到复选框列表.

感谢和问候,

Jagdish .Net


I have an interesting scenario, that I have managed to get working, but I want to throw this out to see if there is a better or "official" way I should be doing things.  I'd like to ideally create a generic custom control to handle this, but right now I order to populate the custom control that contains the checkbox list I'm tied to code written behind a screen and implementing each CheckBox list is cumbersome at best.  

Base requirement:

-  Create CheckBox List as a custom control
-  Options in the CheckBox list bind to a end user updateable list of choices (Option entity below)
-  Checked items need to be saved and retrieved and are associated with a "Report" (Report Options entity below)
-  Need to use the Application Data entities (so no Views in the database and no custom WCF RIA services, unless someone can explain how to do either with Application Data) 

Application Data:

Report [1] -> [N] Report Options [N] -> [1] Option

Currently when the screen gets created for this, the Report Options show as a Data Grid, that contains a drop down choice of each item in the Option entity.  This works, but we are trying to create a form-like experience for UX, and a CheckBox List is more apparent and usable for the end user than a bunch of tabs w/ Data Grids.  

Conceptually what I'm trying to accomplish is to LEFT OUTER JOIN all Option entities, with Report Option entities for 1 Report, and pass that result into my custom control, so I can display all the available Pptions, and only check those that have been saved in the Report Options entity.  

 

In my Report Detail screen, this is what I currently have in the code behind for combining the two Entity sets together into something the CheckBox List can use:

 

  partial void ReportDetail_Activated()
  {
   var proxy = this.FindControl("CheckBoxList");
   proxy.ControlAvailable += OnControlAvailable;
  }

  private void OnControlAvailable(object sender, ControlAvailableEventArgs e)
  {
   this.Details.Dispatcher.BeginInvoke(() =>
   {
    EntitySet<Options> options = this.DataWorkspace.ApplicationData.Options;
    ObservableCollection<ISelectableItem> checkboxListItems = new ObservableCollection<ISelectableItem>();
    
    foreach (Option o in options)
    {
     checkboxListItems.Add(new SelectableItem<Option>(false, o.Description, o));
    }

    foreach (ReportOption j in this.ReportOption)
    {
     foreach (SelectableItem<Option> cb in checkboxListItems)
     {
      if (cb.Text == j.Option.Description)
      {
       cb.IsSelected = true;
      }
     }
    }

    Dispatchers.Main.BeginInvoke(() =>
    {
     _checkboxListItems.Clear();

     foreach (ISelectableItem i in checkboxListItems)
     {
      _checkboxListItems.Add(i);
     }

     CheckboxList cbl = e.Control as CheckboxList;
     cbl.DataContext = _checkboxListItems;

     _isInitalized = true;
    });
   });
  }

解决方案

Hello RyanCain,

             I am new in light switch. I am asp.net developer and currently jump to light switch application.

             I need to implement Check box List control in light switch and get selected check box value from Check box List when final save click. Also bind this Check box List control using store procedure.

             Please help me i had goggling so much but.........

             In my custom control Check box list not found in system.widows.

Thanks and regards,

Jagdish .Net


这篇关于复选框列表自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆