How to autoselect the last record filtered in the Dropdown Grid
Hello,
I have a requirement to ensure a fast form encoding, my form is composed of multiple fields and SfMultiColumnDropDownControl.
I need to automatically select the last item corresponding to the text I enter in the SfMultiColumnDropDownControl without being forced to press the "enter" key.
Can you help me based on the project in attachment and this gif :
Thank you very much
Attachment: SfMultiColumnDropDownControlAutoSelect_dcbc6412.rar
Hi Nicolas Wagener,
We have analyzed your query and provided sample. To achieve your requirement “To select the last item corresponding to the text you enter” you can set the DropDownGrid’s SelectedItem as Item. It will set the last Item of FilterRecord. Kindly review the sample and let us know if you have any concerns on this .
If we have misunderstood your requirement, kindly provide additional details about your requirement. This will help us understand the problem better and provide you with an appropriate solution.
Code Snippet :
|
protected override bool FilterRecord(object item) {
string searchText = this.SearchText.ToLowerInvariant(); switch (FilteredColumnsType) { case FilteredColumnsTypeEnum.BeginsWith: if (propertyNameValue.ToLowerInvariant().StartsWith(searchText)) {
this.GetDropDownGrid().SelectedItem = item; return true; } else continue;
case FilteredColumnsTypeEnum.Contains: if (propertyNameValue.ToLowerInvariant().Contains(searchText)) return true; else continue; case FilteredColumnsTypeEnum.EndsWith: if (propertyNameValue.ToLowerInvariant().EndsWith(searchText)) return true; else continue; }
}
return false;
|
Image Reference :
|
|
Attachment: SfMultiColumnDropDownControlAutoSelect_89c564fa.zip
Hello Sweatha,
I think you mistunderstood my requirement, I will try to rephrase it :
For example, when I type the input text filter "1001" here is what should happen :
Pressing 1 : the popup show up and output 2 records : 1001 and 1002
Pressing 0 : the popup stays open with the same 2 record : 1001 and 1002
Pressing 0 : the popup stays open with the same 2 record : 1001 and 1002
pressing 1 : the popup shows only one record : 1001
pressing "enter" : the popup close and the selected record is 1001.
That's the current behavior.
What I need : when the filtered text correspond to one and only one record -> it automatically select it while I don't need to press "enter".
For the same example, I need this behavior :
Pressing 1 : the popup show up and output 2 records : 1001 and 1002
Pressing 0 : the popup stays open with the same 2 record : 1001 and 1002
Pressing 0 : the popup stays open with the same 2 record : 1001 and 1002
pressing 1 : the selected item is set and the popup is close
Do you understand my explanation this way ?
Thank you.
Nicolas
Hi Nicolas Wagener,
Your requirement "The selected item is set, and the popup is close" can be achieved by hooking the KeyUp event. We modified the sample based on your requirement.
Kindly refer the below code snippet:
|
public CustomCombo() { Loaded += ComboMulti_Loaded; AutoGeneratingColumn += ComboMulti_AutoGeneratingColumn; KeyUp += CustomCombo_KeyUp; }
private void CustomCombo_KeyUp(object sender, KeyEventArgs e) { foreach (var item in this.GetDropDownGrid().RowGenerator.Items) { if (item.RowData != null) { PropertyInfo[] propertiesInfos = item.RowData.GetType().GetProperties(); var filteredCount = FilteredColumns.Count; foreach (var property in propertiesInfos) { if (FilteredColumns.Contains(property.Name)) { var val = property.GetValue(item.RowData).ToString(); if (this.SearchText.ToLowerInvariant().Equals(val.ToLowerInvariant())) { this.IsDropDownOpen = false; break; } } } } } } |
Find the sample in the attachment.
We hope this helps. Please let us know, if need any further assistance.
Regards,
Chidanand M.
Attachment: SfMultiColumnDropDownControlAutoSelect_fb3a9bea.zip
Hi Chidanand,
Sorry for my late response.
It works well for my scenario because we enter the full Id like "1001".
Unfortunately I did not precice the first requirement : " automatically select the last item corresponding to the text I enter ".
So in addition to the first scenario, I would like to add this one :
Actually : Pressing 6 -> the popup show up and one record is in the grid 6255
What i need : Pressing 6 -> the popup can be shown but as soon as it is the only one result in the popup datagrid, I need to automatically select it and close the popup.
Unfortunately, I don't see a proper way of doing that, I have to enter the full Id to automatically select it and close the popup.
Thank you for your time
Nicolas
Nicolas Wagener,
We have addressed your concerns and modified the sample based on your scenario. We have provided the sample for your reference. Kindly review the sample and let us know if you have any concerns
Attachment: SfMultiColumnDropDownControlAutoSelect_b828f588.zip
- 5 Replies
- 3 Participants
-
NW Nicolas Wagener
- Aug 16, 2023 09:52 AM UTC
- Aug 25, 2023 01:15 PM UTC