ComboBox Choices

tbpowers

Active member
Joined
Dec 12, 2011
Messages
41
Programming Experience
Beginner
I am totally new to VB.NET and Visual Studio. I am creating a new form, which includes a combobox. I have figured out how to add the items to the combobox using the properties box, but I would rather code them. I tried the below code, but no luck. Any ideas what I am doing wrong?
Me.cboSTATUS.Items.Add("A")

Any help will be greatly appreciated.
 
It should work. It won't show up in the text area. Click the down arrow to see the listing. If you want it to show in the text area, then do this:

cboSTATUS.Text = "A"
 
Don't forget to add it to the Form Load event if you want the items adding when the form opens.
VB.NET:
me.cboSTATUS.Items.Add("Item1")
 
Ok it worked. What if I want to call a stored procedure to populate this combobox? I found some code on the internet. Do I have to include the SQL connection code if I have already created a dataset connection using the Visual Studio wizard? Here is the code, but Visual Studio does not recognize "cmd".

cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "STP_STATUS"
 
I tried the following, but nothing shows up in the drop down combobox.

Dim SQLCon As New SqlClient.SqlConnection
Dim cmd As New SQLCmdSQLCon.ConnectionString = "Data Source="
SQLCon.Open()

SQLCmd.Connection = SQLCon 'Active Connection
SQLCmd.CommandText = "STP_REPAIR_STATUS"
SQLCmd.CommandType = CommandType.StoredProcedure
SQLCon.Close()
 
Back
Top