473,396 Members | 1,743 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,396 software developers and data experts.

Populating comboBox

hi..

i want to fill my combobox from the values which im having in my table in the database. and my combobox name is combobox1 and my table is tblDetails, and this table having two columns code and name. i want code values to the cobobox.

here is my code which i tried to do
Expand|Select|Wrap|Line Numbers
  1.   this.comboBox1.DataSource = ds.Tables["tbldetail"];
  2.   this.comboBox1.DisplayMember = "Code";//column display name
  3.   this.comboBox1.ValueMember = "code";//actual column name
  4.  
ds the dataset.

this is not working. can some one tell me what was the wrong that im doing here.
Nov 20 '09 #1
6 3739
GaryTexmo
1,501 Expert 1GB
What's the error you're having? I just set up an example using the *exact same code you just posted and it's actually working for me, so I'm wondering if you've got a mistake somewhere in your code, or if I set my test table up differently than you did.

In addition to letting us know what your error actually is (or how it's not working), maybe check to make sure your table actually contains data at that point, as well as the column names. It's all I can think of with what you've given so far.

As a side note, bound controls can sometimes not work how you would like. Sometimes it's a good idea to copy the data from your datatable into the combobox manually. I'm not saying you have to do this, but it is an option :)

*by exact, I mean those three lines using a data table I manually set up and inserted rows into
Nov 20 '09 #2
Curtis Rutland
3,256 Expert 2GB
@buterfly0707
So, you say your two column names are "code" and "name"....but look at your code: you used "Code" and "code".

Also, the column names are case sensitive in the .NET data set.

For future reference:
"It's not working." is usually not enough for us to help you on. If you have errors, please explain exactly what is not working, and provide the exception name and text.
Nov 20 '09 #3
GaryTexmo
1,501 Expert 1GB
@insertAlias
I was going to point out the same, but I tested it and it actually works. So either column names aren't case sensitive, or DisplayMember ignores case. To be honest though, I am by no means an expert on this kind of thing, so there may be something else going on (with regards to why it accepts "Code" and "code").
Nov 20 '09 #4
Curtis Rutland
3,256 Expert 2GB
Hmmm, apparently I was assuming the case sensitive part. You know, when you assume something long enough, you start to think that it's fact.

Regardless, the names he used aren't the same as the names he said his columns were called.
Nov 20 '09 #5
thanks for your replies.

Actually i am not getting any errors or warnings. But its not bounding the values to the combobox from database table.
Nov 23 '09 #6
GaryTexmo
1,501 Expert 1GB
Is your combobox coming up empty? Are there blanks where your selections should be, or is it a completely empty combo box?

It couldn't hurt to check your names as insertAlias suggested, but maybe you should confirm that your database (in those columns) actually contains data. Like I said, I did a pretty quick test with a dataset that I populated manually and it actually worked, so that leads me to believe something might be up with your data. It's a guess, but it should be pretty easy to confirm. Set a breakpoint where you're binding data to your combobox and just use the debugger to see what's in the dataset.
Nov 23 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nicolae Fieraru | last post by:
Hi All, Could somebody provide me step by step instructions of how to populate a combobox with values from a table (any table from northwind.mdb will do). What I have done is: - I added on the...
2
by: Robert | last post by:
I'm sure this is a fairly basic question, but I've been looking all over the web for days for suggestions on how to do this. I've got a datagrid that's bound to a dataset on my form. It includes...
2
by: John Ninan | last post by:
I am creating Dynamic Usercontrol in Asp.net application. In this application I have a combobox(aspx Page). Which contains various items. Based on item selected I am dynamically populating...
4
by: Keith | last post by:
Hello - this started out as a minor annoyance - and now is starting to bother me more and more - I'm hoping someone can help me. I would like to have a combobox display - NOT initially be blank...
2
by: Bill Brinkworth | last post by:
in vb.net 2005, i would like to pull up a name from a database (customers) (i can do this already), then after a name is selected from a combox box, to populate the form's text boxes with with data...
4
by: c_shah | last post by:
I am a beginner and learning VB.net There are two wasy to bind a combobox or a listbox First approach is to assign a datasource and displaymember Second approach is to iterate through datarow...
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: Paul Hadfield | last post by:
I'm looking for thoughts on the "correct" design for this problem (DotNet 2.0 - in winforms, but that's not so important). I've got two combo boxes (combo1 and combo2), both are populating via...
4
by: yaaara | last post by:
Hi, Here's another problem that I came up with: I have a combobox in a form with 2 columns. What I need is the following: 1. The combobox to be cleared on form_load (not only the text, but...
3
by: davenumber40 | last post by:
I’m creating a small database in Access 2003(XP) to track issues during software testing. As far as databases go, it’s going to be a relatively small, short term project (No more than 20,000 records...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.