Results 1 to 7 of 7

Thread: [SEMI-RESOLVED] Problem with removing ListView's ColumnHeader

  1. #1

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    [SEMI-RESOLVED] Problem with removing ListView's ColumnHeader

    I have come accross a strange problem while removing ListView's ColumnHeader.

    Here's a sample code (works with ListView1 and Command1):
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim lX As Long
      Dim liItem As ListItem
      
      ListView1.View = lvwReport
      ListView1.ColumnHeaders.Add 1, , "1"
      ListView1.ColumnHeaders.Add 2, , "2"
      ListView1.ColumnHeaders.Add 3, , "3"
      
      For lX = 1 To 10
        Set liItem = ListView1.ListItems.Add
        
        liItem.Text = lX
        liItem.SubItems(1) = lX * 2
        liItem.SubItems(2) = lX * 3
        
        Set liItem = Nothing
      Next lX
    End Sub
    
    Private Sub Command1_Click()
      ListView1.ColumnHeaders.Remove 1
      ListView1.Refresh
    End Sub
    When i try to remove the 1st column, it seems to work, but, all data is "copied" to the 2nd column. I just can't get it to work correctly.

    Am i missing something?

  2. #2

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Problem with removing ListView's ColumnHeader

    OK. I have managed to sort my situation (which is far more complex) with a work-around. But this still puzzles me...

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [SEMI-RESOLVED] Problem with removing ListView's ColumnHeader

    What workaround are you using... One workaround that I can think of is hiding the entire column... by setting it's width to 0... just a thought..
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [SEMI-RESOLVED] Problem with removing ListView's ColumnHeader

    @kollsid: that's exactly what i'm trying to avoid

    My workaround resets all the values in the column that was not removed. Of course, this takes some unneccessary time.

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [SEMI-RESOLVED] Problem with removing ListView's ColumnHeader

    My workaround resets all the values in the column that was not removed. Of course, this takes some unneccessary time.
    Yeah, I was thinking about this as well... What I mean is copying the data from the listview to an array and after deleting the column add the necessary data back...

    let me play around with it... let's see if there is an easier method...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [SEMI-RESOLVED] Problem with removing ListView's ColumnHeader

    Ok try this

    Code:
    Option Explicit
    Dim lX As Long
    Private Sub Form_Load()
        Dim liItem As ListItem
        ListView1.View = lvwReport
        ListView1.ColumnHeaders.Add 1, , "1"
        ListView1.ColumnHeaders.Add 2, , "2"
        ListView1.ColumnHeaders.Add 3, , "3"
        For lX = 1 To 10
            Set liItem = ListView1.ListItems.Add
            liItem.Text = lX
            liItem.SubItems(1) = lX * 2
            liItem.SubItems(2) = lX * 3
            Set liItem = Nothing
        Next lX
    End Sub
    
    Private Sub Command1_Click()
        Dim Ar(), i, j, k, itm, liItem
        
        ReDim Ar(ListView1.ListItems.Count, ListView1.ColumnHeaders.Count - 2)
        
        i = 0
        
        For Each itm In ListView1.ListItems
            For j = 0 To (ListView1.ColumnHeaders.Count - 2)
                Ar(i, j) = itm.SubItems(j + 1)
            Next j
            i = i + 1
        Next
    
        ListView1.ListItems.Clear
    
        ListView1.ColumnHeaders.Remove 1
    
        For j = LBound(Ar) To UBound(Ar) - 1
            Set liItem = ListView1.ListItems.Add
            liItem.Text = Ar(j, 0)
            For k = 0 To (ListView1.ColumnHeaders.Count - 2)
                liItem.SubItems(1) = Ar(j, k + 1)
            Next
        Next
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [SEMI-RESOLVED] Problem with removing ListView's ColumnHeader

    This is practically the same as my procedure, only a little faster. Ty

    However, few people can work on this app at real time. If some data changes, my procedure updates it (from DB).

    I'm still not satisfied with eather solution. I'll dig more into LV's Remove() method.

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