简体   繁体   English

TextBox AutoComplete在vb.net中不起作用

[英]TextBox AutoComplete not working in vb.net

I'm trying to add auto complete to a VB.NET windows forms textbox. 我正在尝试将自动完成功能添加到VB.NET Windows窗体文本框。 I have a text box of size 268, 102 placed on a form. 我在表格上放置了一个大小为268、102的文本框。 I have tried several ways to get the autocomplete to work: Adding strings to the AutoCompleteCustomSource via the Properties pane Adding a list of strings to a source and assigning that in code - multiple different ways Neither of these make any autocompleteing happen... 我尝试了几种使自动完成功能起作用的方法:通过“属性”窗格将字符串添加到AutoCompleteCustomSource中,将字符串列表添加到源中并在代码中进行分配-多种不同的方式,这两种方法均不会导致任何自动完成操作...

Most recent code attempt is pretty much the example shown on MSDN: 最近的代码尝试几乎是MSDN上显示的示例:

Dim I2cMonths As New AutoCompleteStringCollection()

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    '...
    I2cMonths.AddRange(New String() {"January", "Febuary", "March"})
    With I2C_TextBox
        .AutoCompleteCustomSource = I2cMonths
        .AutoCompleteMode = AutoCompleteMode.SuggestAppend
        .AutoCompleteSource = AutoCompleteSource.CustomSource
    End With
    '...
End Sub

What am I doing wrong?? 我究竟做错了什么??

Try changing the order around... 尝试改变顺序...

     I2C_TextBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    12C_Textbox.AutoCompleteSource = AutoCompleteSource.CustomSource
       I2cMonths.AddRange(New String() {"January", "Febuary", "March"})        
     12C_TextBox.AutoCompleteCustomSource = 12cMonths

Given your description of the case, I suspect your TextBox is MULTILINE. 根据您对案件的描述,我怀疑您的TextBox是MULTILINE。 Standard AutoComplete doesn't work in multiline textboxes. 标准自动完成功能在多行文本框中不起作用。

If you want AutoComplete in a multiline textbox, you'll have to implement it yourself using the appropriate events of the TextBox and processing an on-the-fly list(view)-"pop-up" or some other equivalent. 如果要在多行文本框中使用“自动完成”,则必须使用TextBox的适当事件并处理动态列表(视图)-“弹出窗口”或其他等效项来自己实现。

Try this snippet 试试这个片段

    I2cMonths.AddRange(New String() {"January", "Febuary", "March"})     
    With I2C_TextBox 
       .AutoCompleteMode = AutoCompleteMode.SuggestAppend
       .AutoCompleteSource = AutoCompleteSource.CustomSource
       .AutoCompleteCustomSource = I2cMonths
    End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM