0

i have a structure in a module that i instanciate a table of its type

Public Structure Client
    Public _nom As String
    Public _prenom As String
    Public _age As Integer
End Structure

Module Module1
    Public TableauClient(0) As Client
End Module

that i need to populate nd resize every time i hit a certain button

Dim Dimension As Integer = 0

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            TableauClient(Dimension)._nom = TextBox1.Text.ToString()
            TableauClient(Dimension)._prenom = TextBox2.Text.ToString()
            TableauClient(Dimension)._age = Val(TextBox3.Text)
            Dimension += 1
            ReDim TableauClient(Dimension)
End Sub

the problem is i need to fill a listbox with all the elements in the table when i hit another button but i don't even know where to start to do this, tried datasource or add item by item by using concatenations between the three fields but still couldn't get it right

1
  • 1
    The smart way you be to use a Class instead of a structure, and a List instead of an array. There are examples of this here, here and also here. Commented Oct 29, 2014 at 17:52

1 Answer 1

0

you can still use the structure but, I think it will be easier to work with class. Instead of Array make a list

dim TableauClient as new List(of Client)

create toString inside your class / structure

Public Overrides Function ToString() As String
   return _nom 
End Function

and just add those into your listbox

listbox.items.add(TableauClient (0))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.