Solved

More Combo box binding Problems!

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

20 Experts available now in Live!

Get 1:1 Help Now