Back to Devexpress

RepositoryItemTextEdit.CustomizeAutoCompleteSource Event

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemtextedit-4a8840ba.md

latest8.2 KB
Original Source

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.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

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.

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

TextEdit

AutoCompleteCustomSource

AutoCompleteSource

AutoCompleteMode

UseAdvancedMode

RepositoryItemTextEdit Class

RepositoryItemTextEdit Members

DevExpress.XtraEditors.Repository Namespace