Click here to Skip to main content
15,886,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
<pre lang="vb">
I have a stored procedure that I mus fill in the combobox!
The procedure contains "SELECT ID, name from TblData" and below I will post my codei've done so far!
And I would like someone to help me continue :S Ehere is my error

VB
Dim n As New KonekcijaBaza
       Dim con As New SqlConnection
       con = n.GetCon()

       Dim cmd As New SqlCommand
       cmd.CommandText = "[AP245_IsplatniListi].[PolniComboDirekcii]"
       cmd.CommandType = CommandType.StoredProcedure


       Dim da As New SqlDataAdapter
       Dim ds As New DataSet

       da.SelectCommand = cmd
       da.Fill(ds)



and in teh foram load I have

VB
Dim dbl As New DBLevel
       Dim dv As New DataView
       dv = dbl.PolniCombodirekcija().Tables(0).DefaultView

       cmbDirekci.DisplayMemberPath = "direkcija""
       cmbDirekci.SelectedValue = "sifra_direkcija""
Posted
Updated 4-Jun-13 0:03am
v2

1 solution

The simplest solution is to set the ItemsSource on the combo box equal to the the data table you have just filled. Then define the DisplayMemberPath and SelectedValuePath properties as the names of the columns you wish to A) be the display member and b) be the selected value.

Alternatively (and my preferred approach), is to create a Class of your object type, then populate a collection of of your objects based on the results in the dataset. then use the object collection to populate the combo box.

However, that is generally because I am doing various things with the object that gets selected in my combo boxes.
 
Share this answer
 

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