Solved

More Combo box binding Problems!

Posted on 2004-08-18
2
158 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 50 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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