Back to Devexpress

TextEdit.CustomizeAutoCompleteSource Event

windowsforms-devexpress-dot-xtraeditors-dot-textedit-7c924a00.md

latest6.7 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event TextEditCustomizeAutoCompleteSourceEventHandler CustomizeAutoCompleteSource
vb
<DXCategory("Events")>
Public Event CustomizeAutoCompleteSource As TextEditCustomizeAutoCompleteSourceEventHandler

Event Data

The CustomizeAutoCompleteSource event's data class is TextEditCustomizeAutoCompleteSourceEventArgs. The following properties provide information specific to this event:

PropertyDescription
CharIndexGets the caret position in the current line.
CustomSourceAllows you to specify custom auto-complete suggestions for the current word (EditingWord).
EditingWordGets the current word that the user is typing.
HandledGets 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).
LineIndexGets the current line index (in a multi-line text editor).
LineTextGets 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.

csharp
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;
}
vb
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

UseAdvancedMode

AutoCompleteMode

AutoCompleteSource

TextEdit Class

TextEdit Members

DevExpress.XtraEditors Namespace