Ideas on types of lists

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
hi guys, im looking for some advise on diffent types of lists, im kinda looking for a one for all list,

im sorry f im using the wrong terminalogy but here it goes,

i am looking for a list that is kind of hierarchy like, small example.

The list almost like a class, (eg list.service)

Services:
parent
child
child
child

parent
child
child
child

at first thought i was thinking of using XML, as far as i know its a form of HTML and uses tags. i started looking at an artical on the MSDN and it started talking about headers :S. so im gessing that went out the window.

can anyone give me any ideas and if you can find the time and the articals, point me in the riht direction for information on how to implement it.

thanks guys
 
You're not just looking for a list. The list just provides the list functionality. The relationship would be provided by a property. E.g.
Friend Class Thing

    Private _children As New List(Of Thing)

    Public Property Name As String

    Public ReadOnly Property Children As List(Of Thing)
        Get
            Return _children
        End Get
    End Property

End Class
You create a List(Of Thing) yourself to contain all the top-level items. Each of them has a Children property that contains all its child Thing objects. Each of them has the same and son on, as deep as you like. This exactly how the TreeView works: it has a Nodes property that contains all the top-level TreeNodes and each of them has a Nodes collection that contains its children and so on. You can traverse the entire hierarchy using recursion.
 
hi, thanks for the reply, that makes sense and i iwll probably use that method, my only issue is, i need to be able to let the user to modify the list's, so i think i need to write the list's to a file or some other method of saving. thats why i thought of the XML, as XML uses tags but as i mentioned i read something about headers and thought it was wrong. i also has an idea of using a HTML file and using something like a regular expression for saving and reading, any ideas on best way to save and load multiple list's would rather avoid using a txt filew and stream reader as this would result and quite a few txt files :D again i thought of the the XML and tags to seperate the lists :D. thanks for input
 
XML is a good option for persisting hierarchical data. If you annotate your class appropriately, you can use XML serialization to save or load an arbitrarily large object graph in about four lines of code. You should do some reading on XML serialization.
 
hello again, i hvae looked a bit at XML serialisation and i have started to build the list i need, but i am starting to get really confused lol.

VB.NET:
<XmlRoot("Damage List")> _
Public Class Damagelist

    Public Property Name As String

    <XmlAttribute("Services")>
    Private _Services As New List(Of Damagelist)

    Public ReadOnly Property Services As List(Of Damagelist)
        Get
            Return _Services
        End Get
    End Property
End Class

if i try to add onto the 'Child' part of this class, then im going to get double XML roots and i can see their is going to be many mistakes, i also dont understand how i am ment to ADD stuff to that, i think i am missing something really simple or i am trying to over complecate things lol

thanks
 
sorry, i dont meant to spam the thread, i finally got it to work. dont know how many times i have edited this lol,
everything to.SelectedItem = Nothing.SelectedItem = Nothing do with the XML is done,i am using this code to get the XML data
just to let you know the me.CB_... is a combobox
VB.NET:
Dim objStreamReader As New StreamReader("C:\Product.xml")
        Dim Damagelist As New Damagelist
        Dim x As New XmlSerializer(Damagelist.GetType)
        Damagelist = CType(x.Deserialize(objStreamReader), Damagelist)
        objStreamReader.Close()
        With Me.CB_Sprayless
            .DisplayMember = ("Name")
            .SelectedValue = Damagelist.Sprayless
            .DataSource = Damagelist.Sprayless
        End With
        With Me.CB_Spraying
            .DisplayMember = ("Name")
            .SelectedValue = Damagelist.Spraying
            .DataSource = Damagelist.Spraying
        End With
        With Me.CB_Fiber
            .DisplayMember = ("Name")
            .SelectedValue = Damagelist.Fiber
            .DataSource = Damagelist.Fiber
        End With
        With Me.CB_Aroma
            .DisplayMember = ("Name")
            .SelectedValue = Damagelist.Aroma
            .DataSource = Damagelist.Aroma
        End With
        With Me.CB_Glass
            .DisplayMember = ("Name")
            .SelectedValue = Damagelist.Glass
            .DataSource = Damagelist.Glass
        End With

this populates the comboboxes with that should aprear the name of the list and the list it's self here is wht the object looks like
VB.NET:
<Spraying >
    <Service>
      <Name>Standard</Name>
      <Items>
        <string>Front O/S Bumper Corner</string>
        <string>Front N/S Bumper Corner</string>
        <string>Front Bumper Centre</string>
        <string>Rear O/S Bumper Corner</string>
        <string>Rear N/S Bumper Corner</string>
        <string>Rear Bumper Centre</string>
        <string>Front O/S Wing</string>
        <string>Front N/S Wing</string>
        <string>Rear O/S Quarter Panel</string>
        <string>Rear N/S Quarter Panel</string>
        <string>Front O/S Door</string>
        <string>Front N/S Door</string>
        <string>Rear O/S Door</string>
        <string>Rear N/S Door</string>
        <string>Front O/S Door Sill</string>
        <string>Front N/S Door Sill</string>
        <string>Rear O/S Door Sill</string>
        <string>Rear N/S Door Sill</string>
      </Items>
as i was saying the combobox shows the name and should also contain the list.

but my only problem is how do i access the list property form the comboboxes? i will messy around and see what i can figure out, but in the mean time, can i get some help please

EDIT: Got it working, just declaiored a new service then got it to = the one form the combobox

VB.NET:
Dim service As New Service
        Try
            Damage_List.Items.Clear()
        Catch
        End Try
        If CheckBox_SSR.Checked = True Then
            service = CType(Me.CB_Sprayless.SelectedItem, DamageListClasses.Service)
            For Each item In service.Items
                Me.Damage_List.Items.Add(item)
            Next
        ElseIf CheckBox_Spray.Checked = True Then
            service = CType(Me.CB_Spraying.SelectedItem, DamageListClasses.Service)
            For Each item In service.Items
                Me.Damage_List.Items.Add(item)
            Next
        ElseIf CheckBox_Glass.Checked = True Then
            service = CType(Me.CB_Glass.SelectedItem, DamageListClasses.Service)
            For Each item In service.Items
                Me.Damage_List.Items.Add(item)
            Next
        ElseIf CheckBox_Fiber.Checked = True Then
            service = CType(Me.CB_Fiber.SelectedItem, DamageListClasses.Service)
            For Each item In service.Items
                Me.Damage_List.Items.Add(item)
            Next
        ElseIf CheckBox_Aroma.Checked = True Then
            service = CType(Me.CB_Aroma.SelectedItem, DamageListClasses.Service)
            For Each item In service.Items
                Me.Damage_List.Items.Add(item)
            Next
        End If
 
Last edited:
Back
Top