(VB)组合框具有美国价值 [英] (VB) combobox with United States values

查看:64
本文介绍了(VB)组合框具有美国价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些旧代码,可以使组合框能够自动完成并填充每个状态。我想避免逐行输入。如何才能使此代码生效? 

I've found some old code to make a combobox capable of auto complete and filled with each state. I'd like to avoid typing it line by line. How can I get this code to work? 

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Dim vState As String


        'Combo box is filled with state abbreviations
        For Each vState In Array("ME", "NH", "VT", "MA", "CT", "RI", "NY", "VA", "NC",
    "SC", "GA", "FL", "DE", "NJ", "OH", "MI", "IL", "IN", "IA", "KS", "NE", "OK",
    "TX", "AL", "TN", "MO", "ND", "SD", "WY", "MT", "ID", "NV", "WA", "OR", "CO",
    "NM", "AZ", "WV", "PA", "CA", "AR", "HI", "MN", "WI", "MD", "MS", "AK", "LA",
    "UT", "KY")
            cmbState.Items.Add(vState)
        Next




推荐答案

您好

以下是一些可能有用的代码。

Here is some code that may be helpful.

注意:我在列表中包含了一个.Sort,如果不需要,则只需删除该行。

NOTE: I have included a .Sort on the list so if not needed then just remove the line.

' Form1 with ComboBox named 'cmbState'
Option Strict On
Option Explicit On
Public Class Form1
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim states As New List(Of String)({"ME", "NH", "VT", "MA", "CT", "RI", "NY", "VA", "NC", "SC", "GA", "FL", "DE", "NJ", "OH", "MI", "IL", "IN", "IA", "KS", "NE", "OK", "TX", "AL", "TN", "MO", "ND", "SD", "WY", "MT", "ID", "NV", "WA", "OR", "CO", "NM", "AZ", "WV", "PA", "CA", "AR", "HI", "MN", "WI", "MD", "MS", "AK", "LA", "UT", "KY"})

    ' remove if sort not needed
    states.Sort()

    With cmbState
      .DataSource = states
      .AutoCompleteMode = AutoCompleteMode.SuggestAppend
      .AutoCompleteSource = AutoCompleteSource.ListItems
    End With
  End Sub
End Class


这篇关于(VB)组合框具有美国价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆