Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Pretty basic question I hope ... I am trying to create a Windows Form that will allow the user to choose a League from a ComboBox and then send E:Mails depending on what he chooses in a second ComboBox.

It is not for use over a network, just on one person's PC so I don't have to worry about massive security issues.

I have designed the Form and I have a very basic SQL database as part of the Project, the form has a BindingSource, a BindingNavigator and a TableAdapter all included.

The question is, how do I populate the first ComboBox with the data that is in the Leagues DataSet ? Can I do this, is this data freely available or do I still have to go down the path of creating a ConnectionString and all the DataTable, DataSet, DataAdapter variables etc., etc. ?

VS2010 automatically gives me the following code ...

VB
Private Sub KAmail_Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'DB_KAmailDataSet.Leagues' table. You can move, or remove it, as needed.
    Me.LeaguesTableAdapter.Fill(Me.DB_KAmailDataSet.Leagues)
End Sub


... can I do something similar to "Fill" the ComboBox with the League Names ? The following code adds 1 line per League to the ComboBox, but it's not the Value of the entry, it is a text line that says "KAmail.DB_KAmailDataSet+LeaguesRow" ...

VB
For MyIx = 0 To DB_KAmailDataSet.Leagues.Count - 1
    KAmail_ComboBox1.Items.Add(Me.DB_KAmailDataSet.Leagues.Item(MyIx))
Next


This is the CodeProject article that I used to base my work on ... Quickest Way to Create a .NET Database Application[^]
Posted

1 solution

Set the datasource of your combobox to be list of objects returned from your data layer. then set this displaymember to be the member that has the string to show, or just override ToString to rendedr the value you want. Then the selected item will be your item, and it will all work fine.
 
Share this answer
 
Comments
Gary Heath 7-Jan-14 13:46pm    
Thank you, I still have trouble understanding most of this stuff, but I got it working :-)

Thanks again ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900