Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

More Combo box binding Problems!

Posted on 2004-08-18
2
Medium Priority
?
161 Views
Last Modified: 2011-10-03
I have a combo box which should populate with 'States' (NSW, QLD, VIC, WA etc.).
I then expect it to get it's value from the database just like all the other bound fields when I fill the dataset containing POHEADER table.

I have the following settings:

A DataSet called DsPurchaseOrder1 which contains a table called POHEADER.

A combo box called cmbState which has a collection of values (NSW, QLD, VIC, WA etc.)
The combo box has the following properties:

SelectedValue is DsPurchaseOrder1 - POHEADER.PO_SUPP_STATE

Why won't the combo box dispaly the value from POHEADER.PO_SUPP_STATE?

What should i put in the ValueMember property? I believe I need something here so that when the value has been changed by the user and we want to update the database it needs to know what value to use. Or does it just use the displayed text if this property is left blank?

Are there any other properties that need to be set on the combo box to do what I'm trying to do?

I seem to be able to get this to work on other combo boxes where the datasource is another table in the dataset rather than a collection of values.
Is this the only way to do it? I don't really want to create a table in the database or dataset for a static table such as States.

Thanks in Advance.
Marnie.
0
Comment
Question by:MarnieHook
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
karthikeyanTP earned 150 total points
ID: 11841009
If you are not using another dataset, you need to bind tha t combo box to an arrya of State objects. You need to set valuemember and display member property to the property of the state object.

Structure state
        Public stateID As String
        Public stateName As String
        Public Sub New(ByVal name As String, ByVal id As String)
            Me.stateID = id

            Me.stateName = name
        End Sub
        Public Property getShort() As String
            Get
                Return stateID
            End Get
            Set(ByVal Value As String)
                stateID = Value
            End Set
        End Property
        Public Property getLong() As String
            Get
                Return stateName
            End Get
            Set(ByVal Value As String)
                stateName = Value
            End Set
        End Property
    End Structure

'Then you can create a state object and intialize it.
 Private myState() As state = New state() {New state("Alaska", "AL"), New state("Arizona", "AZ")}

'The binding of the combo box is as follows
       ComboBox1.DataSource = myState
        ComboBox1.DisplayMember = "getLong"
        ComboBox1.ValueMember = "getShort"
        ComboBox1.DataBindings.Add("SelectedValue", ds.Tables("perInfo"), "memSecUSstate")


0
 

Author Comment

by:MarnieHook
ID: 11889712
Thankyou, I have used an array now.. back to how I was originally going to do it... but have to have 2 arrays since I have two 'State' COmbo boxes. Bit of a nuisance but I guess that's teh way it has to be for now... until I get brainy at this stuff and think of a better idea.
Thanks for your help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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