Solved

More Combo box binding Problems!

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now