473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

c# combo box populating

JC
Hi all,

I have a combobox control in a c# form. I would like to populate this
drop down with values from a dataset- so have written a procedure to
populate a dataset.

Once created I am using this code to populate the combobox...

DataSet ds = new DataSet();
ds = im.getAllOnline();//a function that return a dataset
comboBox1.DataSource = ds.Tables["IM"];
comboBox1.DisplayMember = "username";
comboBox1.ValueMember = "userIp";

I have checked the dataset, and it is being populated, but for some
reason I cannot get the combobox to work.

I would really appreciate help with this cos its driving me nuts!!!
Nov 15 '05 #1
7 63691
Hi James

if it's a webcontrol you have to bind the data to the grid
comboBox1.DataBind();
"JC" <ja*********@btinternet.com> wrote in message
news:d7**************************@posting.google.c om...
Hi all,

I have a combobox control in a c# form. I would like to populate this
drop down with values from a dataset- so have written a procedure to
populate a dataset.

Once created I am using this code to populate the combobox...

DataSet ds = new DataSet();
ds = im.getAllOnline();//a function that return a dataset
comboBox1.DataSource = ds.Tables["IM"];
comboBox1.DisplayMember = "username";
comboBox1.ValueMember = "userIp";

I have checked the dataset, and it is being populated, but for some
reason I cannot get the combobox to work.

I would really appreciate help with this cos its driving me nuts!!!

Nov 15 '05 #2
Hi,

You should establish a binding between the combo box and the data source
instead. Please refer to the documentation on the
System.Windows.Forms.Binding class as well as Control.Bindings collection in
MSDN.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"JC" <ja*********@btinternet.com> wrote in message
news:d7**************************@posting.google.c om...
Hi all,

I have a combobox control in a c# form. I would like to populate this
drop down with values from a dataset- so have written a procedure to
populate a dataset.

Once created I am using this code to populate the combobox...

DataSet ds = new DataSet();
ds = im.getAllOnline();//a function that return a dataset
comboBox1.DataSource = ds.Tables["IM"];
comboBox1.DisplayMember = "username";
comboBox1.ValueMember = "userIp";

I have checked the dataset, and it is being populated, but for some
reason I cannot get the combobox to work.

I would really appreciate help with this cos its driving me nuts!!!


Nov 15 '05 #3
Thanks for replying Stefan,

The combo box in question is on a windows form, not a web form. For some
reason the control does not have a DataBind() option that you woudl
expect - thats what I'm finding confusing.

Any ideas?

Thanks

JC

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4
Hi Dmitriy,

Thanks for the tip I'll read the articles!

I cant link to the datasource direct cos I'm using a seperate layer to
grab the data, and passing it over as a dataset - so I still have a
little problem.

Thanks for the advice though.

JC

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5
James,

DataSets and DataTables actually are the most widely used data sources for
the Windows Forms binding - so it's just what you need!

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"James Crane" <ja*********@btinternet.com> wrote in message
news:O7*************@TK2MSFTNGP11.phx.gbl...
Hi Dmitriy,

Thanks for the tip I'll read the articles!

I cant link to the datasource direct cos I'm using a seperate layer to
grab the data, and passing it over as a dataset - so I still have a
little problem.

Thanks for the advice though.

JC

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 15 '05 #6

Thanks everyone for your help - I think I've cracked it now.

As per Miscro$t site, I went through the dataset and created an
arrayList. I passed this to the combobox and it worked!!
Happy days

Thanks again

JC
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #7

Thanks everyone for your help - I think I've cracked it now.

As per Miscro$t site, I went through the dataset and created an
arrayList. I passed this to the combobox and it worked!!
Happy days

Thanks again

JC
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff_F | last post by:
Hi all. Question in two parts. I'm looking to add two combo boxes. The first will contain regions and the second will contain employee names which correspond to the region selected in the first...
3
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the...
2
by: visionstate | last post by:
Hi there, I am working on a form that uses 3 text boxes and 3 combo boxes. When any data is entered into any of these, I click a command button and this requeries a sub query in the form and...
2
by: docsix | last post by:
I am having trouble populating a combo box in a subform. Currently I have two combo boxes on a single form that works. This is my current setup: Table:Facilities - FacilityID ... FacilityType 1...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
7
by: blazted | last post by:
I am having a problem with populating a combo box from a Access DB, I am calling a stored procedure that executes with one row of values. i want to populate those values into my combo box but right...
1
by: gdixon | last post by:
Greetings To All! I am using a Access 2003 and my programing skills are of the cut and paste variety. This means begining programming skills and on a good day perhaps middle of the road...
0
by: Dawnyy | last post by:
I have a form which is bound to a dataset. I am filling the forms dataset on Form_Load event. On my form I have combo boxes which I am setting by running a stored procedure to return a datatable,...
11
by: jgoodnight | last post by:
Hi, I have a form with three combo boxes: Area, Sub-Area, and Factor. I've set up the Sub-Area combo box to list only those areas that are part of the selected area. I've set up the Factor combo...
0
pod
by: pod | last post by:
I am new to OOD and n-tier architecture but I want to start the right way. In Visual Studio, I have created a solution with three projects c/w reference to each other i.e. the Business Logic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.