Results 1 to 6 of 6

Thread: [RESOLVED] Adding a column to a listview that already has columns

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Resolved [RESOLVED] Adding a column to a listview that already has columns

    Hi

    I'm new to VB6 (I usually program in VB.NET but have been asked to make an enhancement to a VB6 application).

    I have a listview which has columns defined within it in the designer. The code I am looking at then retrieves data from a db and puts it into the listview.

    I've been asked to add another column in the middle of the listview e.g. there are 10 columns defined in the designer and this new column needs to go at position 6. However, the data that needs to go in the new column needs to come from a different query than the one that fills the other columns. I therefore thought that the best way to do it was fill up the original columns and then slot in the new column and fill it from another query. I've been searching around but can't find any example of how to do this.

    Please can anyone help, or suggest a better way to do it? Thanks!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Adding a column to a listview that already has columns

    How you populate it is up to you, but I think the easiest way to add it would be in design and have it be a permenant part of the control.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: Adding a column to a listview that already has columns

    Thanks, I've managed to tweak the SQL query so that I can get all I need in the same query.

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Adding a column to a listview that already has columns

    Try this code and see if it fits the bill:

    Option Explicit

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim lvwItem As MSComctlLib.ListItem
    3. Dim lvwCol As MSComctlLib.ColumnHeader
    4. Dim a As Long
    5.     'This will load the Listview with the initial data
    6.     With ListView1
    7.         .View = lvwReport
    8.         .ColumnHeaders.Clear
    9.        
    10.         For a = 1 To 3
    11.             Set lvwCol = .ColumnHeaders.Add(, "Col" & a, "Col " & a, .Width / 3)
    12.         Next a
    13.    
    14.         For a = 1 To 20
    15.             Set lvwItem = .ListItems.Add(, "_" & a)
    16.             lvwItem.Text = "Item " & a
    17.             lvwItem.SubItems(2) = a & " SubItem 2"
    18.         Next a
    19.     End With
    20.  
    21. Set lvwItem = Nothing
    22. Set lvwCol = Nothing
    23. End Sub
    24.  
    25. Private Sub Command2_Click()
    26. Dim a As Long
    27.  
    28.     With ListView1.ListItems
    29.         For a = 1 To .Count
    30.             .Item(a).SubItems(1) = "New Value " & a
    31.         Next a
    32.     End With
    33. End Sub
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: [RESOLVED] Adding a column to a listview that already has columns

    [QUOTE=Mark Gambo]Try this code and see if it fits the bill:

    QUOTE]

    Thanks Mark, I'll take a look at that!

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Adding a column to a listview that already has columns

    You may have to add some sort of search feature inorder to match up the values properly, buit I agree with Hack that tweeking your SQL String is the better way to go.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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