.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理

例如:有部门和员工两个ListView

1.      首先用模型编辑器添加一个DashboardView1

2.      然后再给DashboardView1添加两个ItemDepartment_ListView Employee_ListView;

3.      代码

using System;

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
using System.Collections;
using DevExpress.Data.Filtering;

namespace EasyTestTool.Module
{
    
public partial class EmployeesDashboardInteractionController : ViewController<DashboardView>
    {
        
public EmployeesDashboardInteractionController()
        {
            InitializeComponent();
            RegisterActions(components);
        }

        
private const string TargetDashboardId = "DashboardView1";
        
private const string EmployeeCriteriaId = "SelectedDepartmentsCriteria";


        
private ListView employeeListView;
        
private ListView departmentListView;

        
protected override void OnActivated()
        {
            
base.OnActivated();

            
if (View.Id == TargetDashboardId)
            {
                
foreach (DashboardViewItem item in View.GetItems<DashboardViewItem>())
                {
                    item.ControlCreated 
+= item_ControlCreated;
                }
            }
        }

        
void item_ControlCreated(object sender, EventArgs e)
        {
            DashboardViewItem item 
= ((DashboardViewItem)sender);

            
if (item.Frame.View.Id == "Department_ListView")
            {
                departmentListView 
= (ListView)item.Frame.View;
                departmentListView.SelectionChanged 
+= departmentListView_SelectionChanged;
            }

            
if (item.Frame.View.Id == "Employee_ListView")
            {
                employeeListView 
= (ListView)item.Frame.View;
            }
        }

        
void departmentListView_SelectionChanged(object sender, EventArgs e)
        {
            ArrayList keys 
= new ArrayList();
            
object selectObject = null;
            
foreach (object selectedObejct in ((ListView)sender).SelectedObjects)
            {
                
if (selectedObejct != null)
                    keys.Add(ObjectSpace.GetKeyValue(selectedObejct));
            }

            FilterEmployeeListView(
new InOperator("Department", keys));
       }
        
         

        
private void FilterEmployeeListView(CriteriaOperator criteria)
        {
            employeeListView.CollectionSource.Criteria[EmployeeCriteriaId] 
= criteria;
        }

        
protected override void OnDeactivated()
        {
            
base.OnDeactivated();

            
if (View.Id == TargetDashboardId)
            {
                
foreach (DashboardViewItem item in View.GetItems<DashboardViewItem>())
                {
                    item.ControlCreated 
-= item_ControlCreated;
                }

                
if(departmentListView != null)
                {
                    departmentListView.SelectionChanged 
-= departmentListView_SelectionChanged;
                }
            }


        }
    }
}

 

posted on 2011-05-04 14:20  Tonyyang  阅读(1260)  评论(1编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/