PowerShell:为DropDownList提供与HTML选择

时间:2016-03-20 18:16:27

标签: powershell

有没有办法让一个ComboBox格式化为DropDownList与HTML select相同的功能?

我的意思是,如果您输入字母" Es",下拉列表会自动选择第一个值为" ES *"就像HTML选择的情况一样? 现在,通过输入第二个字母,列表跳转到" Ssp1"而不是" Esp1"

有什么想法吗?

HTML参考:https://jsfiddle.net/j7h2326c/4/

PowerShell示例:

    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()

2 个答案:

答案 0 :(得分:2)

将ComboBox自动完成模式设置为Append

$combobox1.AutoCompleteMode = 'Append'

答案 1 :(得分:0)

Avshalom向我指出了正确的方向。那里只缺少两件事:

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

所以完整的代码是:

    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()