Solved

More Combo box binding Problems!

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

777 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