Vb.net 什么';使用Visual Basic在Windows应用程序中创建下拉列表的最佳方法是什么?

Vb.net 什么';使用Visual Basic在Windows应用程序中创建下拉列表的最佳方法是什么?,vb.net,visual-studio,Vb.net,Visual Studio,我想在Windows应用程序中添加一个下拉列表。它将有两个选项,其中任何一个都不可编辑。最好使用什么控件?它是编辑属性设置为“否”的组合框吗 我使用的是Visual Studio 2008。yourComboBox.DropDownStyle=ComboBoxStyle.DropDownListyourComboBox.DropDownStyle=ComboxStyle.DropDownList我建议看一下。听起来你最好使用单选按钮,或者,如果这是一种明确的开/关类型的情况,使用复选框。不过,我

我想在Windows应用程序中添加一个下拉列表。它将有两个选项,其中任何一个都不可编辑。最好使用什么控件?它是编辑属性设置为“否”的组合框吗


我使用的是Visual Studio 2008。

yourComboBox.DropDownStyle=ComboBoxStyle.DropDownList
yourComboBox.DropDownStyle=ComboxStyle.DropDownList
我建议看一下。听起来你最好使用单选按钮,或者,如果这是一种明确的开/关类型的情况,使用复选框。不过,我想我们真的需要更多的信息。

我建议看一下。听起来你最好使用单选按钮,或者,如果这是一种明确的开/关类型的情况,使用复选框。不过,我认为我们确实需要更多信息。

将DropDownStyle属性设置为DropDownList


请参见将DropDownStyle属性设置为DropDownList


请参见

通过将DropDownStyle属性更改为“DropDownList”,winforms中的combobox将作为不可编辑的下拉列表加倍:我认为没有单独的下拉列表控件。

通过将DropDownStyle属性更改为“DropDownList”,winforms中的combobox将作为不可编辑的下拉列表加倍:我认为没有单独的下拉列表控件。

在TextBox1和TextBox2旁边创建两个文本框,为TextBox2设置多行并自动调整大小

在某处创建您的下拉列表。在我的例子中,它是在一个不同的表中,有大约13000个条目

下面是两个功能,第一个驱动输入框TextBox1。键入时,第二个框TextBox2显示剩余的有效选项。第二个函数,如果单击第二个框中的选项,则加载第一个文本框

在下图中,当前工作表上的单元格B3必须加载键入/选定的答案。在我的应用程序中,我只想搜索大写字符,因此使用UCase。我的列表数据是Z列中的13302个条目

Private Sub TextBox1_Keyup(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim curtext As String
Dim k, where As Integer
Dim tmp As String
Dim bigtmp As String
curtext = TextBox1.Text
curtext = UCase(curtext)
TextBox1.Text = curtext
Range("b3").Value = curtext
If Len(curtext) = 0 Then
TextBox2.Visible = False
Exit Sub
End If

TextBox2.Visible = True
Application.ScreenUpdating = False
For k = 2 To 13303                                      '  YOUR LIST ROWS
  tmp = Sheets("General Lookup").Range("Z" & k).Value   '  YOUR LIST RANGE
  where = InStr(1, tmp, TextBox1.Text, 1)
  If where = 1 Then
  bigtmp = bigtmp & tmp & Chr(13)
  End If
Next

TextBox2.Text = bigtmp
Application.ScreenUpdating = True
End Sub

Private Sub TextBox2_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If Len(TextBox2.SelText) > 0 Then
    TextBox1.Text = TextBox2.SelText
    Range("b3").Value = TextBox2.SelText
    TextBox2.Visible = False
    End If
End Sub

为TextBox2创建两个相邻的文本框TextBox1和TextBox2设置多行并自动调整大小

在某处创建您的下拉列表。在我的例子中,它是在一个不同的表中,有大约13000个条目

下面是两个功能,第一个驱动输入框TextBox1。键入时,第二个框TextBox2显示剩余的有效选项。第二个函数,如果单击第二个框中的选项,则加载第一个文本框

在下图中,当前工作表上的单元格B3必须加载键入/选定的答案。在我的应用程序中,我只想搜索大写字符,因此使用UCase。我的列表数据是Z列中的13302个条目

Private Sub TextBox1_Keyup(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim curtext As String
Dim k, where As Integer
Dim tmp As String
Dim bigtmp As String
curtext = TextBox1.Text
curtext = UCase(curtext)
TextBox1.Text = curtext
Range("b3").Value = curtext
If Len(curtext) = 0 Then
TextBox2.Visible = False
Exit Sub
End If

TextBox2.Visible = True
Application.ScreenUpdating = False
For k = 2 To 13303                                      '  YOUR LIST ROWS
  tmp = Sheets("General Lookup").Range("Z" & k).Value   '  YOUR LIST RANGE
  where = InStr(1, tmp, TextBox1.Text, 1)
  If where = 1 Then
  bigtmp = bigtmp & tmp & Chr(13)
  End If
Next

TextBox2.Text = bigtmp
Application.ScreenUpdating = True
End Sub

Private Sub TextBox2_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If Len(TextBox2.SelText) > 0 Then
    TextBox1.Text = TextBox2.SelText
    Range("b3").Value = TextBox2.SelText
    TextBox2.Visible = False
    End If
End Sub

是的,我认为单选按钮实际上会工作得更好。谢谢是的,我认为单选按钮实际上会工作得更好。谢谢