天天看點

vb.net中combobox與數組綁定

Dim lbstr() As String = {"集團檔案", "紅頭檔案", "各店通知", "學習資料", "常用檔案"}
        Dim lbvalue() As String = {"集團通知", "紅頭檔案", "各店通知", "學習資料", "常用資料"}
        Dim dt As New DataTable
        dt.Columns.Add("名稱")
        dt.Columns.Add("值")
        cmb_lb.Items.Clear()
        Dim i As Integer = 0
        For i = 0 To lbstr.Length - 1
            Dim arow As DataRow = dt.NewRow
            arow(0) = lbstr(i).ToString
            arow(1) = lbvalue(i).ToString
            dt.Rows.Add(arow)
        Next
        cmb_lb.DataSource = dt
        cmb_lb.DisplayMember = "名稱"
        cmb_lb.ValueMember = "值"
           

兩個數組一個存内容一個存值,然後讀入到datatable,最後combobx的資料源設定為datatable就可以了.