Solved

Populate Combbobox in DataRepeater

Posted on 2009-07-05
14
357 Views
Last Modified: 2013-11-26
Hi Experts

I have a Combo box in a data repeater witch I want to populate with a few values from a MS access database. I use the following code to try and populate the Combo box:

        Vehicle_NameComboBox.DataSource = TransportInfoSys_beDataSet.Tables("Vehicles")
        Vehicle_NameComboBox.DisplayMember = "Vehicle_Name"

But when i run this command there doesn't happen anything.

Any help would be greatly appreaciated

Thanx in advance
Vehicle_NameComboBox.DataSource = TransportInfoSys_beDataSet.Tables("Vehicles")

        Vehicle_NameComboBox.DisplayMember = "Vehicle_Name"

Open in new window

0
Comment
Question by:Benvor
  • 7
  • 6
14 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24783069
First, I would suggest not using the reader.  Create a dataset and dataadapter and set the datasource of the combobox = dataset.  From there you can set the display member and value member.  Here is the code:


Dim dataset As New DataSet
 

Using connection As New SqlConnection(connectionString)

   Dim adapter As New SqlDataAdapter()

   adapter.SelectCommand = New SqlCommand("select Name,ID from tblName", connection)

   adapter.Fill(dataset)

End Using
 

ComboBox1.DataSource = dataset.Tables(0)

ComboBox1.DisplayMember = "Name"

ComboBox1.ValueMember = "ID"

Open in new window

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24783072
Using a datareader, you can't use the binding !
Dim strConnect as Strng

strConnect = Session("ConnectionString") 
 

' Open the Connection 

Dim Con as new System.Data.SQLClient.SQLConnection(strConnect) 

Con.Open() 
 

' SQL Statement

Dim strSQL as String

strSQL = "SELECT State_Name, State_Code FROM TableState ORDER BY State_Name"
 

' Command, Data Reader 

Dim Com as new System.Data.SQLClient.SQLCommand(strSQL, Con) 

Dim rdr as System.Data.SQLClient.SQLDataReader = Com.ExecuteReader() 
 

' Populate the Control 

While rdr.Read()

   Dim newListItem as new ListItem() 

   newListItem.Text = rdr.GetString(0)

   newListItem.Value = rdr.GetString(1) 

   DropDownList1.Items.Add(newListItem) 

End While

Open in new window

0
 

Author Comment

by:Benvor
ID: 24783100
Sorry but I'm confused, witch code must I use now?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24783172
You'll have to make a choice :)

I you want to use the binding like you set in your question, you'll need the first solution
0
 
LVL 9

Expert Comment

by:Rahul Goel
ID: 24783201
Add one more line

Vehicle_NameComboBox.DataBind()
0
 

Author Comment

by:Benvor
ID: 24783230
'Databind' is not a member of 'System.Windows.Forms.Combobox'.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24783250
is your datatable filled before you do this:
Vehicle_NameComboBox.DataSource = TransportInfoSys_beDataSet.Tables("Vehicles")
Vehicle_NameComboBox.DisplayMember = "Vehicle_Name"

If not, you need to fill it like I mentioned in the first post
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Benvor
ID: 24783270
Here are everything I have on my Form, and they fill on FormLoad
untitled.bmp
0
 

Author Comment

by:Benvor
ID: 24783785
The adapter fills correctly, but the combo box on the data repeater still doesn't fill
0
 

Author Comment

by:Benvor
ID: 24783801
I've just tried it with a combo box that is not on the data repeater, and it filled it up completely with the correct values. But as soon as the combo box is dragged onto the data repeater it doesn't fill anymore
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 24785001
I think it is databound comboboxes that the datarepeater cannot cope with. No idea why not, very frustrating!.

I've found this link:
http://www.vbforums.com/showthread.php?referrerid=61394&t=535556

Just drag a new combobox with no databindings from the toolbox, set its items manually in the itemcloned event using the bindingsource and an arraylist (see example in link) and then set its selected index in the drawitem  event using a hidden databound label control

That'll have to do for now.

Comment from expert pedsys found at http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23961065.html
0
 

Author Comment

by:Benvor
ID: 24811359
Hi Dhaest

I tried to get the code to work but I'm not sure what I must replace this piece of code with? Can you please help me

            VDP_Array.Add(New mdlStrDefs.ComboListData("Ea", 1))
            VDP_Array.Add(New mdlStrDefs.ComboListData("Sf", 2))
            VDP_Array.Add(New mdlStrDefs.ComboListData("Lf", 3))

"Type 'mdlStrDefs.ComboListData' is not defined"
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24811372
What data do you want to store in your combobox ? Is it a list of strings, objects, ...
0
 

Author Comment

by:Benvor
ID: 24811406
It is a list of vehicles(Display Member) and each one has a ID(Value Member)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm development 2 39
Tabcontrol Caption? 1 25
Hide Tab Page 3 20
Connect to a database from Excel using JDBC instead of ODBC 3 32
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now