BaseListBoxControl.ParseSearchControlText Event
Fires when a related SearchControl fires a query to the current List Box. Allows you to create a filter condition based on the query and specify how to highlight results in the control.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v24.2.dll
Declaration
[DXCategory("Data")]
public event EventHandler<ParseSearchControlTextEventArgs> ParseSearchControlText
Event Data
The ParseSearchControlText event's data class is DevExpress.XtraEditors.ParseSearchControlTextEventArgs.
Remarks
The SearchControlText event argument returns the query in the search control. Based on the query, you can create a CriteriaOperator object that specifies a filter condition. To apply the condition to the control, use the SetFindCriteriaAndHighlight method.
Example
The code below shows how to use a comma to split the search query into several queries.
using DevExpress.Data;
using DevExpress.Data.Filtering;
private void listBoxControl1_ParseSearchControlText(
object sender, DevExpress.XtraEditors.ParseSearchControlTextEventArgs e) {
if(string.IsNullOrWhiteSpace(e.SearchControlText))
return;
List<string> criteria = new List<string>();
foreach(string criteriaString in e.SearchControlText.Split(new[] { ',' },
StringSplitOptions.RemoveEmptyEntries)) {
string str = criteriaString;
if(criteriaString[0] == ' ')
str = criteriaString.Remove(0, 1);
criteria.Add(str);
}
if(criteria.Count < 2)
return;
string filterString = String.Empty;
for(int i = 0; i < criteria.Count; i++) {
filterString += "Contains([LastName], '" + criteria[i] + "')";
if(i != criteria.Count - 1)
filterString += " OR ";
}
CriteriaOperator _findCriteria = CriteriaOperator.Parse(filterString);
e.SetFindCriteriaAndHighlight(_findCriteria,
(x) => {
var arr = new DisplayTextHighlightRange[criteria.Count()];
for(int i = 0; i < criteria.Count(); i++) {
arr[i] = new DisplayTextHighlightRange(x.IndexOf(criteria[i]), criteria[i].Length);
}
return arr;
});
e.Handled = true;
}