RepositoryItemTextEdit.CustomizeAutoCompleteSource Event
Allows you to dynamically supply custom auto-complete text suggestions 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.Repository
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
When the AutoCompleteMode option is set to SuggestSingleWord
and the AutoCompleteSource option is set to CustomSource
, you can supply custom auto-complete suggestions for words entered in the text editor as follows:
- Use the
CustomizeAutoCompleteSource
event to supply custom auto-complete suggestions dynamically. For example, you can supply auto-complete suggestions based on the caret position within the edit box, or based on the typed word. You can also handle this event to display auto-complete suggestions that contain the currently typed word (see the example below). - Use the TextEditAdvancedModeOptions.AutoCompleteCustomSource collection to supply the default collection of auto-complete suggestions. The editor filters this collection to display those auto-complete items that start with the edit word. The TextEditAdvancedModeOptions.AutoCompleteCustomSource property has lower priority than the
CustomizeAutoCompleteSource
event.
The CustomizeAutoCompleteSource
event triggers every time a user types or deletes a character in the edit box.
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;
}