Solved

Binding combobox selectedvalue to a dataview column

Posted on 2004-08-04
7
961 Views
Last Modified: 2008-01-16
I have a few comboboxes on my form that I fill through code. Now I want to bind the selected value of those comboboxes to information contained in my dataview. I tried

    cboHairColor.DataBindings.Add("SelectedValue", dv, "Hair")

as well as DisplayMember and SelectedItem instead of SelectedValue but it's not showing any data in the field.

This is the code I use to bind my text boxes to my dataview, so not sure what's not working for my comboboxes.
0
Comment
Question by:bng0005
  • 4
  • 2
7 Comments
 
LVL 1

Author Comment

by:bng0005
ID: 11720817
If I do:

cboHairColor.DataBindings.Add("Text", dv, "Hair")

it will show the information, but is it the correct one to use?
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11720999
Did you try ??

cboHairColor.DataSource = dv
cboHairColor.DisplayMember = "column to display"
cboHairColor.ValueMember = "Hair"

-Baan
0
 
LVL 1

Author Comment

by:bng0005
ID: 11721621
I fill the combobox options on the form load like this:

        cboHairColor.Items.Add("AU")
        cboHairColor.Items.Add("BD")
        cboHairColor.Items.Add("BK")

so I can't set the datasource to the dataview. The dataview is a filtered version of my records, with the combobox being used to display one of those fields, if that makes sense
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:bng0005
ID: 11722032
Gonna try to explain the problem a little better since it doesn't sound all that clear to me and it's my question heh.

I have a dataset that has all the customer information to be displayed in my UI. Most of the fields are displayed in textboxes and binding those to my dataview is simple enough. A few need to be bound to comboboxes. These comboboxes have their options filled in manually since they each only have like 4 or 5 different options, so I don't have a dataview of the different options to bind to the datasource of the comboboxes. What I would like to have happen is that in my main dataview, have the data for that column display in that combobox if it exists.

If it can be done this way without changing my code, great. I would like to do it that way if possible.

If I have to redo my combobox code and not add in items manually, how would I get a dataview set up with a table containing all of the items to be included in the combobox?
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 250 total points
ID: 11722187
cool... it is nice and clear to me now...

well, keep your comboBoxes... as they are (manually added). Then you can use DataReader with proper selection of Sql Query, and display the data in the TextBoxes.
eg:  Dim SqlStr as String = SELECT * From Emp WHERE State = '" & ComboBox1.SelectedItem.ToString() & "'"
0
 
LVL 1

Expert Comment

by:xorcrack
ID: 11722849
Use:
       
cboAccountStatus.DataBindings.Add("SelectedValue", dv, "hair")

or

cboAccountStatus.DataBindings.Add("SelectedText", dv, "hair")
0
 
LVL 1

Author Comment

by:bng0005
ID: 11727477
Baan,

The combobox isn't used for SQL selection, only display existing data in my dataview. I just want to bind the combobox to one of the columns in my dataset so the data shows in the textbox area if it exists, and if it doesn't, they can use the options in the combobox to ensure proper data entry. Pretty much I want it to act like just another text box, but still provide options for the user to select when adding records. Here's my crappy combobox art to try and explain:

 __________________________________
 |dataset info here if it exists or blank |\/ |
 ------------------------------------------------
 |Options to select down here                  |
 |if no data for that row                           |
 |                                                          |
 ------------------------------------------------

Xor,

I already tried that, doesn't work for manual items added to combobox I guess. I use the exact same code for a different combobox where I set the datasource to a table within my database. I am trying to avoid adding 2 extra tables with like 5 or 6 entries each if I can.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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