I want to know it is posible to filters **LookUpEdit ** dropdown list by the column that corresponds to the ValueMember value.
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 = ""
I using devexpress 14.2.3. and vb.net
You can display in your LookUpEdit additionally "VALUE" column, that will allow you to search. Or you can overwrite search mechanism.
EDIT: Eases way, i think, is display value column, like this:
<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>
So or you can override LookUpEdit. Sorry, i dont know how it correct write on VB, but idea similar:
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;
}
}
or override OnAutoSearchTextChanged in LookUpEdit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.