StUffz
StUffz

Reputation: 123

PowerShell: giving DropDownList the same functionality as with HTML select

Is there any way to give a ComboBox formatted as a DropDownList the same functionality as with HTML select?

What I mean is that if you type the letters "Es", the dropdownlist automatically selects the first value with "ES*" as it would be the case with HTML select? Right now, by entering the second letter, the list jumps to "Ssp1" instead of "Esp1"

Any ideas?

HTML reference: https://jsfiddle.net/j7h2326c/4/

PowerShell Example:

    Add-Type -AssemblyName System.Windows.Forms
    $form = New-Object System.Windows.Forms.Form
    $combobox1 = New-Object System.Windows.Forms.ComboBox
    $form.Controls.Add($combobox1)


    $combobox1.Location = '30,30'
    $combobox1.DropDownStyle = 'DropDownList'
    $combobox1.Items.AddRange(@('Term add 1', 'Term add 2', 'Term more 1', 'Esp1', 'Esp2', 'Ssp1'))

    $form.ShowDialog()

Upvotes: 1

Views: 4789

Answers (2)

StUffz
StUffz

Reputation: 123

Avshalom pointed me to the right direction. There where only two things missing:

$combobox1.AutoCompleteSource = 'ListItems'
$combobox1.AutoCompleteMode = 'Append'

so the complete code would be:

    Add-Type -AssemblyName System.Windows.Forms
    $form = New-Object System.Windows.Forms.Form
    $combobox1 = New-Object System.Windows.Forms.ComboBox
    $form.Controls.Add($combobox1)


    $combobox1.Location = '30,30'
    $combobox1.DropDownStyle = 'DropDownList'
    $combobox1.AutoCompleteSource = 'ListItems'
    $combobox1.AutoCompleteMode = 'Append'
    $combobox1.Items.AddRange(@('Term add 1', 'Term add 2', 'Term more 1', 'Esp1', 'Esp2', 'Ssp1'))

    $form.ShowDialog()

Upvotes: 1

Avshalom
Avshalom

Reputation: 8889

Set the ComboBox Auto-complete Mode to Append

$combobox1.AutoCompleteMode = 'Append'

Upvotes: 3

Related Questions