我建议你通过这个 DevExpress 线程来描述大多数情况下实现这个功能。
如何根据第一个 LookUp 列的值过滤第二个 LookUp 列
GridControl、TreeList 和 VGridControl 提供了一个在激活单元格编辑器时引发的特殊事件:ShownEditor。这是将查找编辑器的数据源替换为按适当标准过滤的集合的最佳时机。
例子:
Private Sub gridView1_ShownEditor(ByVal sender As Object, ByVal e As EventArgs)
Dim view As ColumnView = DirectCast(sender, ColumnView)
If view.FocusedColumn.FieldName = "CityCode" AndAlso TypeOf view.ActiveEditor Is LookUpEdit Then
Dim edit As LookUpEdit = CType(view.ActiveEditor, LookUpEdit)
Dim countryCode As String = CStr(view.GetFocusedRowCellValue("CountryCode"))
edit.Properties.DataSource = GetFilteredCities(countryCode)
End If
End Sub
有关使用 LookupEdit 绑定 XPO 对象的更多信息,请查看此 KB 示例:
如何:将 XPCollection 绑定到 LookUp
例子:
XPCollection xpCollectionPerson = new XPCollection(typeof(Person));
xpCollectionPerson.DisplayableProperties = "Name;Group!Key";
gridControl1.DataSource = xpCollectionPerson;
XPCollection xpCollectionGroup = new XPCollection(typeof(PersonGroup));
RepositoryItemLookUpEdit lookUpRI = new RepositoryItemLookUpEdit();
lookUpRI.DataSource = xpCollectionGroup;
lookUpRI.DisplayMember = "GroupName";
lookUpRI.ValueMember = "Oid";
gridControl1.RepositoryItems.Add(lookUpRI);
// Associate the LookUpEdit editor with the "Group!Key" column.
(gridControl1.MainView as ColumnView).Columns["Group!Key"].ColumnEdit = lookUpRI;
希望这有帮助。