Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a List using an array of structures

Status
Not open for further replies.

BigOrangeMonkey

Programmer
Aug 27, 2002
26
0
0
GB
Hi There,

I'm populating a list using an array of type MyStructure but I cant get it to display the description in the list, also when I set the valuemember it gives the error :

An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

Additional information: Could not bind to the new display member.

Heres some code :
Code:
    Private Structure ListContainerStruct
        Dim ProductId As String
        Dim AreaId As String
        Dim GroupId As String
        Dim WorkgroupId As String
        Dim SequenceNo As String
        Dim Description As String
    End Structure

    Private Sub BuildMainList()
        Dim TempWebAreaDefRow As WEBAREADEFINITIONS.webAreaDefinitionsRow
        Dim i As Integer = 0
        Dim MyArray() As ListContainerStruct

        For Each TempWebAreaDefRow In m_WebAreaDefsDS.Tables(0).Rows
            ReDim Preserve MyArray(i)
            With MyArray(i)
                .AreaId = TempWebAreaDefRow.area_id
                .ProductId = TempWebAreaDefRow.product_id
                .Description = TempWebAreaDefRow.description
            End With
            i = i + 1
        Next
        WebAreaDefsLst.DataSource = MyArray
        WebAreaDefsLst.DisplayMember = "Description"
        WebAreaDefsLst.ValueMember = "AreaId"
        WebAreaDefsLst.SelectedIndex = 0
    End Sub

Any Ideas?
Thanks,
Steve.
 
I had this error and i search a couple of hours.
The problem is that DisplayMember and ValueMemmber work only with property of a class or a structure.

Try to change your structure as follow:

Private Structure mListContainerStruct
Private mProductId As String
Private mAreaId As String
Private mGroupId As String
Private mWorkgroupId As String
Private mSequenceNo As String
Private mDescription As String

Public Property ProductId() As String
Get
Return Me.mProductId
End Get
Set(ByVal Value As String)
Me.mProductId = Value
End Set
End Property

'And do the rest of the properties



End Structure
 
Well...what can I say, except check the date of the original post. I really hope BigOrangeMonkey hasnt been sat there twiddling his thumbs and waiting for a solution for almost 3 years.


Sweep
...if it works dont mess with it
 
Wow, I'd forgotten all about that, not even sure I remember exactly what I was writing at the time. I've been involved in a few hundred projects since then :D

CoolWeb I honestly do appreciate the response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top