例如:有部门和员工两个ListView
1. 首先用模型编辑器添加一个DashboardView1
2. 然后再给DashboardView1添加两个Item:Department_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;
}
}
}
}
}
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;
}
}
}
}
}
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/