windowsforms-devexpress-dot-xtraeditors-dot-textedit-7c924a00.md
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.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event TextEditCustomizeAutoCompleteSourceEventHandler CustomizeAutoCompleteSource
<DXCategory("Events")>
Public Event CustomizeAutoCompleteSource As TextEditCustomizeAutoCompleteSourceEventHandler
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. |
This event is equivalent to the RepositoryItemTextEdit.CustomizeAutoCompleteSource event. See the event description for more information.
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;
}
textEdit1.Properties.UseAdvancedMode = DevExpress.Utils.DefaultBoolean.True
textEdit1.Properties.AdvancedModeOptions.AutoCompleteMode = DevExpress.XtraEditors.TextEditAutoCompleteMode.SuggestSingleWord
textEdit1.Properties.AdvancedModeOptions.AutoCompleteSource = AutoCompleteSource.CustomSource
AddHandler textEdit1.Properties.CustomizeAutoCompleteSource, AddressOf textEdit1_CustomizeAutoCompleteSource
Private autoCompleteItems() As String = { "apricot", "apple", "pear", "lime", "lemon", "blueberry", "banana", "pineapple" }
Sub textEdit1_CustomizeAutoCompleteSource(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.TextEditCustomizeAutoCompleteSourceEventArgs)
Dim editingWord As String = e.EditingWord.ToLower()
If String.IsNullOrEmpty(editingWord) Then
e.CustomSource = autoCompleteItems
Else
Dim customSource As New List(Of String)()
For Each item As String In autoCompleteItems
If item.ToLower().Contains(editingWord) Then
customSource.Add(item)
End If
Next item
e.CustomSource = customSource.ToArray()
End If
' Set the Handled parameter to 'true' to display the supplied auto-complete suggestions (e.CustomSource) as is.
e.Handled = True
End Sub
See Also