Devexpress LookUpEdit - 按值成员搜索第二列

时间:2015-02-21 18:39:11

标签: vb.net devexpress

我想知道通过与ValueMember值对应的列过滤** LookUpEdit **下拉列表是可行的。

        LookUpEdit.DataSource = ds.Tables(0)
        LookUpEdit.ValueMember = ds.Tables(0).Columns("VALUE").Caption.ToString
        LookUpEdit.DisplayMember = ds.Tables(0).Columns("DISPLAYtext").Caption.ToString
        LookUpEdit.View.FocusedRowHandle = DevExpress.XtraGrid.GridControl.AutoFilterRowHandle
        LookUpEdit.AllowFocused = True
        LookUpEdit.CloseUpKey = New KeyShortcut(Keys.Add)
        LookUpEdit.NullText = ""

我使用devexpress 14.2.3。和vb.net

1 个答案:

答案 0 :(得分:0)

您可以在LookUpEdit中另外显示" VALUE"列,将允许您搜索。 或者你可以覆盖搜索机制。

编辑: 我认为,缓解方式是显示值列,如下所示:

<dxg:LookUpEdit AutoPopulateColumns="False" ValueMember="VALUE" DisplayMember="DISPLAYtext">
<dxg:LookUpEdit.StyleSettings>
<dxg:SearchLookUpEditStyleSettings/>
</dxg:LookUpEdit.StyleSettings>
<dxg:LookUpEdit.PopupContentTemplate>
<ControlTemplate>
<dxg:GridControl AutoGenerateColumns="None" Name="PART_GridControl">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Value"/>
<dxg:GridColumn FieldName="DISPLAYtext"/>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView NavigationStyle="Row" ShowGroupPanel="False" ShowTotalSummary="False" AutoWidth="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
</ControlTemplate>
</dxg:LookUpEdit.PopupContentTemplate>
</dxg:LookUpEdit>

所以或者你可以覆盖LookUpEdit。对不起,我不知道如何正确写在VB上,但想法类似:

public class MyLookUpEdit : LookUpEdit
{
    public MyLookUpEdit()
    {
        currentItems = new List<TestDataItem>();
    }

    private List<TestDataItem> currentItems;

    protected override void OnDisplayTextChanged(string displayText)
    {
        base.OnDisplayTextChanged(displayText);
        this.currentItems.Clear();
        var filter = (displayText).ToLower();
        foreach (var item in ((IEnumerable<TestDataItem>) this.ItemsSource).Where(x => this.Filter(x, filter)))
        {
            this.currentItems.Add(item);
        }
        currentItems.Sort(new Comparison<TestDataItem>((el1, el2) =>
        {
            int elt1 = CompareStrings(el1.Value, filter);
            int elt2 = CompareStrings(el2.Value, filter);
            return elt2 - elt1;
        }));
        if (GetGridControl() != null)
        {
            GetGridControl().ItemsSource = currentItems;
            Dispatcher.BeginInvoke((Action) (GetGridControl().RefreshData));
        }
    }

    private bool Filter(TestDataItem item, string filter)
    {
        if (filter.Length < 2) return false;
        int res = CompareStrings(item.Value, filter);
        if (res > 1) return true;
        /**/
        return false;
    }

    public int CompareStrings(string str1, string str2)
    {
        int res = 0;
        if (str1 == str2) return 2;
        /**/
        return res == 0 ? 1 : res;
    }
}

或覆盖LookUpEdit中的OnAutoSearchTextChanged