Results 1 to 7 of 7

Thread: [RESOLVED] Listbox confusion

  1. #1

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Resolved [RESOLVED] Listbox confusion

    Hello, I am one confused dog

    I am trying to use a listview in detail view as a sort of flexgrid to show a selection of information in memory. Now I can get the title bar ok and split it into parts but if I try to add more than one 'row' to the list the others blank out. I cannot seem to work out in my head how it works.

    Code:
      Dim I As Long
            Dim ListVI As ListViewItem
    
            With lvDetails
                'Clear All
                .Clear()
    
                .Columns.Add("Site", 200, HorizontalAlignment.Left)
                .Columns.Add("Town", 200, HorizontalAlignment.Left)
                .Columns.Add("PostCode", 100, HorizontalAlignment.Left)
                .Columns.Add("Serial", 100, HorizontalAlignment.Left)
    
                'Create Column Details
                For I = 1 To UBound(Sites)
    
                    'Clear Items
                    ListVI = New ListViewItem(Sites(I).Name)
    
                    ListVI.SubItems.Add(Sites(I).Town)
                    ListVI.SubItems.Add(Sites(I).Postcode)
                    ListVI.SubItems.Add(Sites(I).Serial)
    
                    .Items.Add(ListVI)
    
                Next I
    
    
            End With
    I have even tried 'arraying' the listVI object and then using AddRange but that doesnt work either

    Any pointers would be appreciated
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Listbox confusion

    not sure what you mean by blank out.. if they rows are there but have blank strings as their text? or they don't appear at all..

    2 things in your code that stand out right away are:

    1) you should be using integer instead of long, the fact that you are using long makes me think you have option strict off, which you should really turn on.

    2) your looping from 1 to ubound(array), array indexes start at 0, so unless you are skipping the first element of the sites array on purpose, your code is skipping that element.

    Now these 2 things don't specifically explain your issue per-say, I can tell you this code works fine:

    Code:
        Public Structure SiteInfo
            Dim Name As String
            Dim Town As String
            Dim Postcode As String
            Dim serial As String
        End Structure
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim Sites(3) As SiteInfo
    
            With Sites(0)
                .Name = "Test 1"
                .Postcode = "00001"
                .Town = "Town 1"
                .serial = "001"
            End With
            With Sites(1)
                .Name = "Test 2"
                .Postcode = "00002"
                .Town = "Town 2"
                .serial = "002"
            End With
            With Sites(2)
                .Name = "Test 3"
                .Postcode = "00003"
                .Town = "Town 3"
                .serial = "003"
            End With
            With Sites(3)
                .Name = "Test 4"
                .Postcode = "00004"
                .Town = "Town 4"
                .serial = "004"
            End With
    
            Dim I As Integer
            Dim ListVI As ListViewItem
    
            With lvDetails
                'Clear All
                .Clear()
    
                .Columns.Add("Site", 200, HorizontalAlignment.Left)
                .Columns.Add("Town", 200, HorizontalAlignment.Left)
                .Columns.Add("PostCode", 100, HorizontalAlignment.Left)
                .Columns.Add("Serial", 100, HorizontalAlignment.Left)
    
                'Create Column Details
                For I = 0 To Sites.GetUpperBound(0)
    
                    'Clear Items
                    ListVI = New ListViewItem(Sites(I).Name)
    
                    ListVI.SubItems.Add(Sites(I).Town)
                    ListVI.SubItems.Add(Sites(I).Postcode)
                    ListVI.SubItems.Add(Sites(I).serial)
    
                    .Items.Add(ListVI)
    
                Next I
    
    
            End With
        End Sub

  3. #3
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Listbox confusion

    I have just been thu the listview learning curve mt self

    this may also help

    http://www.vbforums.com/showthread.php?t=493151

  4. #4

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Re: Listbox confusion

    *BANG*
    *BANG*
    *BANG*

    Although my head hurts after that I feel I deserve it. I was being a right retard and setting element 1 in my test array twice instead of setting number 2.

    I feel it is going to be one of those days

    It works now lol. Thanks for the help and I will change that variable to integer. Am I right in saying integers in .net are now the equivilent of longs in vb6?
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Listbox confusion

    yes you are correct in saying that.

    VB6 integer = .NET short (16 bit int)
    VB6 long = .NET integer (32 bit int)

  6. #6

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Re: [RESOLVED] Listbox confusion

    Cheers

    only just moving over and its very confusing when they change things like that. :s
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] Listbox confusion

    I hear ya, but you pick it all up pretty fast.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width