TextEdit.CustomizeAutoCompleteSource Event
Allows you to supply custom auto-complete text suggestions dynamically each time a user types a new word in the text box. This event is in effect in advanced mode when the AutoCompleteSource option is set to CustomSource
, and the AutoCompleteMode option is set to SuggestSingleWord
.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v24.2.dll
Declaration
[DXCategory("Events")]
public event TextEditCustomizeAutoCompleteSourceEventHandler CustomizeAutoCompleteSource
Event Data
The CustomizeAutoCompleteSource event's data class is TextEditCustomizeAutoCompleteSourceEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
CharIndex | Gets the caret position in the current line. |
CustomSource | Allows you to specify custom auto-complete suggestions for the current word (EditingWord). |
EditingWord | Gets the current word that the user is typing. |
Handled | Gets or sets whether to display custom suggestions (CustomSource) in the drop-down list as is, or to filter this list to display only those items in the drop-down that start with the current word being edited (EditingWord). |
LineIndex | Gets the current line index (in a multi-line text editor). |
LineText | Gets the text displayed in the current line. |
Remarks
This event is equivalent to the RepositoryItemTextEdit.CustomizeAutoCompleteSource event. See the event description for more information.
Example
The example below handles the CustomizeAutoCompleteSource event to supply auto-complete suggestions to a text editor. The handler filters the suggestions to display those items that contain the typed word.
textEdit1.Properties.UseAdvancedMode = DevExpress.Utils.DefaultBoolean.True;
textEdit1.Properties.AdvancedModeOptions.AutoCompleteMode = DevExpress.XtraEditors.TextEditAutoCompleteMode.SuggestSingleWord;
textEdit1.Properties.AdvancedModeOptions.AutoCompleteSource = AutoCompleteSource.CustomSource;
textEdit1.Properties.CustomizeAutoCompleteSource += textEdit1_CustomizeAutoCompleteSource;
string[] autoCompleteItems = new string[] { "apricot", "apple", "pear", "lime", "lemon", "blueberry", "banana", "pineapple" };
private void textEdit1_CustomizeAutoCompleteSource(object sender, DevExpress.XtraEditors.TextEditCustomizeAutoCompleteSourceEventArgs e) {
string editingWord = e.EditingWord.ToLower();
if (string.IsNullOrEmpty(editingWord))
e.CustomSource = autoCompleteItems;
else {
List<string> customSource = new List<string>();
foreach (string item in autoCompleteItems) {
if (item.ToLower().Contains(editingWord))
customSource.Add(item);
}
e.CustomSource = customSource.ToArray();
}
// Set the Handled parameter to 'true' to display the supplied auto-complete suggestions (e.CustomSource) as is.
e.Handled = true;
}