Combobox / Arraylist Confusion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce D

    #1

    Combobox / Arraylist Confusion

    I'm confused on the best way to create a combobox with "YES"/"NO" and values
    of "Y""/N". I'm trying this way...but I get an error: Could not bind to the
    new display member

    Public Class combo
    Inherits System.Windows. Forms.Form
    Public Structure sItems
    Public DisplayVal As String
    Public RealVal As String
    End Structure

    Dim arlist As ArrayList
    Dim sList As sItems

    Private Sub combo_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    arlist = New ArrayList
    sList = New sItems

    sList.DisplayVa l = "Yes"
    sList.RealVal = "Y"
    arlist.Add(sLis t)

    sList.DisplayVa l = "No"
    sList.RealVal = "N"
    arlist.Add(sLis t)

    Me.ComboBox1.Da taSource = arlist
    Me.ComboBox1.Di splayMember = "DisplayVal "
    Me.ComboBox1.Va lueMember = "RealVal"
    End Sub
    End Class


    Any help is appreciated!

    -BD


  • Ken Tucker [MVP]

    #2
    Re: Combobox / Arraylist Confusion

    Hi,

    Replace the structure with a class with properties. You can
    only bind to properties in a class.


    Public Class sItems
    Dim mstrVal As String
    Dim mstrReal As String

    Public Property DisplayVal() As String
    Get
    Return mstrVal
    End Get
    Set(ByVal Value As String)
    mstrVal = Value
    End Set
    End Property

    Public Property RealVal() As String
    Get
    Return mstrReal
    End Get
    Set(ByVal Value As String)
    mstrReal = Value
    End Set
    End Property
    End Class

    Ken
    ----------------------
    "Bruce D" <brucexwxduncan x@hotmail.com> wrote in message
    news:11atqu3tbo jcs3e@corp.supe rnews.com...
    I'm confused on the best way to create a combobox with "YES"/"NO" and values
    of "Y""/N". I'm trying this way...but I get an error: Could not bind to the
    new display member

    Public Class combo
    Inherits System.Windows. Forms.Form
    Public Structure sItems
    Public DisplayVal As String
    Public RealVal As String
    End Structure

    Dim arlist As ArrayList
    Dim sList As sItems

    Private Sub combo_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    arlist = New ArrayList
    sList = New sItems

    sList.DisplayVa l = "Yes"
    sList.RealVal = "Y"
    arlist.Add(sLis t)

    sList.DisplayVa l = "No"
    sList.RealVal = "N"
    arlist.Add(sLis t)

    Me.ComboBox1.Da taSource = arlist
    Me.ComboBox1.Di splayMember = "DisplayVal "
    Me.ComboBox1.Va lueMember = "RealVal"
    End Sub
    End Class


    Any help is appreciated!

    -BD



    Comment

    Working...