|
-
Aug 20th, 2007, 04:29 AM
#1
Thread Starter
Lively Member
[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!
-
Aug 20th, 2007, 06:06 AM
#2
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.
-
Aug 20th, 2007, 06:10 AM
#3
Thread Starter
Lively Member
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.
-
Aug 20th, 2007, 06:15 AM
#4
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:
Private Sub Command1_Click()
Dim lvwItem As MSComctlLib.ListItem
Dim lvwCol As MSComctlLib.ColumnHeader
Dim a As Long
'This will load the Listview with the initial data
With ListView1
.View = lvwReport
.ColumnHeaders.Clear
For a = 1 To 3
Set lvwCol = .ColumnHeaders.Add(, "Col" & a, "Col " & a, .Width / 3)
Next a
For a = 1 To 20
Set lvwItem = .ListItems.Add(, "_" & a)
lvwItem.Text = "Item " & a
lvwItem.SubItems(2) = a & " SubItem 2"
Next a
End With
Set lvwItem = Nothing
Set lvwCol = Nothing
End Sub
Private Sub Command2_Click()
Dim a As Long
With ListView1.ListItems
For a = 1 To .Count
.Item(a).SubItems(1) = "New Value " & a
Next a
End With
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."
-
Aug 20th, 2007, 06:17 AM
#5
Thread Starter
Lively Member
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!
-
Aug 20th, 2007, 06:28 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|