How to load a ComboBox with string values?
Posted on 2012-09-02
I got some code from a co-worker some time back that allowed me to populate a ComboBox from an SQL table, but now I need to populate it with a set of string variables instead--not using a table at all. The problem is that I don't understand how to modify this code to do what I need.
I have a ComboBox named txtItem, and I'd like to populate it with three strings named psItemCode1, psItemCode2, and psItemCode3, so I need to understand how to modify the code he gave me. Right now this is what I have to populate it from an SQL table:
'Populating the combobox ----------
Dim ItemTable As Data.DataTable
ItemTable = GetItems()
If ItemTable.Rows.Count > 0 Then
Me.txtItem.DataSource = ItemTable
Me.txtItem.DisplayMember = ItemTable.Columns("Item").ToString
Me.txtItem.ValueMember = ItemTable.Columns("Item").ToString
Me.txtItem.Enabled = True
And the code for GetItems() is:
Public Function GetItems(Optional ByVal DataRead As String = Nothing) As DataTable
Dim Sqlstr As String
Sqlstr = " SELECT Item From Sysitem Order By Item "
Return RunSQLDataTable(Sqlstr, CommandType.Text)
So what do I need to add or remove from this existing code in order to simply populate the ComboBox wtih my three strings? TIA