Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




ListView SubItems


I have a report type listview with one subitem column. I need to allow the user to select and change the information held within the subitem column. I can easily do it with the listitem column but I do not seem to be able to even select the subitem let alone edit it.
Thanks




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Moving A Listview Item And Its Subitems To A New Listview
Hey Guys,

Having a bit of trouble. I am attemping to move a selected item and its subitems from one listview to another. I have no problem getting the contents of the first column, but I can't seem to get the subitems over.

Example: I have this in the first listview:

Code:
|Item |Quanity|Price |PQ |
Bananas 2 $.50 $1.00

Then when I try to move that whole row to the other listview I can only seem to get this:

Code:
|Item |Quanity|Price |PQ |
Bananas

No subitems . Any links or help would be appreciated.

Regards,

Max_Power

Listview With Subitems
Hi,

I'm a newbee on VB 6.0 (old stuff I have to maintain ). Now I have this silly problem that I have a listview with 2 subitems. When I click on one item I would like to get the 1. subitem moved to a listbox. How do i do that?

Hope some can help me

Jan

Listview & Subitems
Hello, i tried some searching in the forum and also in the web. There must be possibilities to edit subitems.

"Garrett Sever" made something like this.

can anyone help?

okay, what i need is the following

listview with:
subitem - text
subitem - boolean value (best as checkbox)

both of them editable


any ideas?

Listview Subitems
hey agin, sorry for all the questions but i am stuck again.

i have a list box and i am loading an array into it. i can set the column headers and the first column but how do i set the subitems. i am using vb 6.0

here is the code i use to load the first colum


Code:
ListAdd.ListItems.Add , , Contact(0)


i need to load

contact(1) and 2

i have tried everything i could think of or get off the net. the examples from mdsn site did not work for me. thanks for the time. Pat

Listview/subitems
hi guys, just got a little stuck and im sure its a simple thing lol, well any way here is my problem, i have created a listview with 2 coulum headers


VB Code:
ListView1.ColumnHeaders.Add , , "Profile", 2970ListView1.ColumnHeaders.Add , , "Type", 970


ok, i have loaded everyting into the first coulum (profile) by useing


VB Code:
Set mItem = ListView1.ListItems.Add(, , "VISTER", , 1)


etc etc etc, now in the coulum header 2 (type) i can add the first bit of code to the first line


VB Code:
mItem.SubItems(1) = "Testl"


now how do i add to the next line down in coulum header 2? can you please help thanks..

ListView Subitems
In other apps where I've used the ListView i've added things like this.


VB Code:
Dim itmX as ListView Set itmX = ListView1.ListItems.AdditmX = Item1itmX.SubItems(1) = Item2itmX.SubItems(2) = Item3'etc....  


However in a new app i've set everything up the same but when I try to complie to EXE i get a message saying "Method or data member not found" and the below code is highlighted. I can't figure out why it's not working

VB Code:
.SubItems(1)

How To Add Subitems To ListView
How to add subitems to ListView?? Is it the best way?

ListView Subitems
Is it posable to display an Icon in a Subitem column of a ListView control in lvwReport view?

Thanks,
Alex

Listview And Subitems
Got a question for you all.

In this program a module called Recoredset.

This is the area of the problem.
---------------------------------------------------------------------

Public Sub Validate(UserName, Password As String)
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Dim SQL As String

SQL = "Select * from Passwords where UserName = " & Chr(34) & UserName & Chr(34)

Rs.Open SQL, conn, adOpenKeyset, adLockReadOnly
With FrmBMServer

If Rs.EOF = True Then .sckServerWinsockConnection(.InitMax).SendData "InValid UserName": Exit Sub
If UCase(Password) = UCase(Rs!Password) Then
.sckServerWinsockConnection(.InitMax).SendData "Password Validated"
.lvUsers.ListItems.Add , , UserName
.lvUsers.ListItems(1).SubItems(1) = Count + 1
.lvUsers.ListItems(2).SubItems(1) = Count + 2 <- Right Here
Else
.sckServerWinsockConnection(.InitMax).SendData "InValid Password"
End If

End With

Rs.Close
Set Rs = Nothing
FrmBMServer.Label7.Caption = Err.Description

End Sub

---------------------------------------------------------------------
The line that has the arrow next to it is my problem.

I have a ListView set up and it has too columnheaders at the top. First column is UserName.
Second Column is Port Number.
What I want it to do is to put user name in the first column row and the port number in the second column row.
Im not sure on how to do this. There's got to be a way to check if column row's 1 2 3 etc are already filled, and if so add a new one plus need to figuer out how to put a counter in for the port numbers.


So it sould look somthing like this.

column Username | Column Port Number
-------------------------------------
Texg | 1
Bill | 2
ect...


Thanks for your help
TexG

Listview Subitems
Well, i just could not stay away from my code, and soon i found areas for improvement, so i´m back.. =)
This is similar to my other listview problem, but i can´t seem to figure it out. I have a listview with Headers
created by this code (thanks to XTab and DaVBMan). sOuput is used to make up the Headers of the listview.

Code:
ListView1.View = lvwReport
arrHeaders = Split(sOutput, ",")
For i = 1 To UBound(arrHeaders) + 1
        ListView1.ColumnHeaders.Add
        ListView1.ColumnHeaders(i).Text = Trim(arrHeaders(i - 1))
Next


I have a another comma separated file that i want to split and then use as subitems in the listview.
File might look like below, but is most likely much larger. I need to first get rid of the first line, then split
the file at every comma, and finaly add each "column" as a sub item in the listview. So in this case all three
"maverick" will go into the first column, bootstrap c: mp and index:maverick will go into the second
column and so on. Who´s got a tip to get me started? I´m really having som problems with my Split routines,
not to mention adding subitems in listviews, so all suggestions are welcome. =)

client,name,date-time
maverick,bootstrap,2004-10-05
maverick,c: mp,2004-10-05
maverick,index:maverick,2004-10-05

The file is read here, and i need to split it somewhere along this line and add the subitems.
Text10 is just used to test the code, i want to replace it with my listview.
Code:
Open "c: est.dat" For Input As #1
    Do While Not EOF(1)
        Label11.ForeColor = &HC000&
        Label11.Caption = "Match found!"
        Text10.Text = input(LOF(1), #1)
    Loop
Close #1
End If




Edited by - Maverick2004 on 10/17/2004 10:55:45 PM

ListView SubItems
Does anyone know of a way to edit values in subitems? What I am trying to achieve is to have the listview populate with values from a table but to allow the user to edit those values and then read the information back to the table.

Listview Subitems Backcolor
Is there any way to change the backcolor of subitems in a listview? Something like this:


Code:
Do Until .EOF
Set itmX = Lvw1.ListItems.Add(, , Rs![F8])
itmX.SubItems(1) = Rs![F1]
itmX.SubItems(2) = Rs![F3]
itmX.SubItems(2) = Trim(itmX.SubItems(2))
itmX.SubItems(3) = Rs![F7]
itmX.SubItems(4) = Rs![F11]
itmX.SubItems(5) = Rs![F12]
itmX.SubItems(6) = Rs![F13]
If Rs![F6] = " " Then
For X = 1 To 6
itmX.Subitems(x).Backcolor = vbred '<=== of course does not work
Next X
End If

Edit Listview Subitems
Hi All,

in the attached picture is an example of the data that i displayed for the user to see in listview. how can i allow the subitems for editing by the users and save the edited datas.

i have searched through forum for similar examples to learn from. however, i am not able to find one. can anyone please help me in this area. thanks a million.

best regards.

Editing ListView SubItems
Is it possible to edit ListView's subitems by clicking on them twice like on the main item and also to select them by clicking only once? And how can I make one column editable and another readonly?

Selecting Subitems In A Listview
I want to make the program select an item of a listview when you click on one of it's subitems/columns. Does anyone know of a good way to do this?

Thx.

ListView's Subitems Question
I added items and subitems into Listview. But, I notice that I can only highlight the item portion (first column) in the Listview, and the subitem portion is inaccessible.

Could somebody give me some advice on how to make the subitem portion highligtable and editable? Thanks a whole bunch for your help. Have a great day!

Listview Tooltip Over SubItems Only?
I'm using this code I found here that works fine for showing each SubItem(1) text in a Tooltip for as the cursor moves over each one. I have 3 columns. Is there a way to show the SubItem(1) Tooltip only when the cursor is over one of the SubItem(1) and not the other columns?

Thanks


Code:
Dim objListItem As MSComctlLib.ListItem
Set objListItem = lstApp.HitTest(x, y)

If Not objListItem Is Nothing Then
lstApp.ToolTipText = objListItem.SubItems(1)
Else
lstApp.ToolTipText = ""
End If

Listview SubItems SmallICon Using ADO
Hi, This is a piece of the code I use to populate the Listview.


Code:
Sub FillListview
Do While Not rs.EOF
Set lvwItem = frmMain.ListView1.ListItems.Add(, , rs.Fields.Item("Field").Value, , "Users") ' << Users = name of Icon in ImageList
lvwItem.SubItems(1) = rs.Fields.Item("Field2").Value & vbNullString
lvwItem.SubItems(2) = rs.Fields.Item("Field3").Value & vbNullString
' ...... etc....


How do I add Icons (Images) to the Listviews Subitem?
I hope that it is possible.
Thanks in advance.

How To Edit Subitems In Listview Vb6?
Is there a way to edit a subitem in listview? I've been searching the forums regarding this but found none. I tried using label edit but i figured that only the 1st column can be edited. It would be nice if a subitem can be edited.

Any suggestions is highly appreciated.

thanks

Listview: Checkbox In SubItems
Dear All,

Is it possible to use checkbox in the subitems of the listview.
If yes, then plz help and guide.


Thanks

Listview Subitems.. Ensurevisible??
How do I get a listview to scroll over so a sub item is visible?

Thanks!

How To Check The Subitems In Listview
hi, anyone tell me the syntax in getting the subitems in the listview using finditem command? tnx!

Hittest On Listview Subitems
Is there any way of implimenting a hittest on listview subitems?

I have several columns open in a listview and when I scroll within the subitem area I want to know which record I am hovering over.

The problem being that when you move off of the main listview item the hittest freezes.


:mike:

Invisible Subitems In A ListView
Is it possible to add subitems to a listview such that they are not displayed (and occupy no space, i.e. there shouldn't be an "empty column")?

The purpose is I want this invisible subitems that musn't be shown to become automatically arranged when I click on a cloumn header to alphabetically arrange the text in each row.

Checkboxes In Listview Subitems
Is it possible to put checkboxes in a listview subitem?

I've seen code that allows you to put pictures in the sub items, but I would like checkboxes.

Thanks.

ListView: SubItems Or ListSubItems?
I have the following called from my Form_Load event.

VB Code:
Private Function Create_Headers()    With lvwData        .View = lvwReport        .FullRowSelect = True        .LabelEdit = lvwManual        .SmallIcons = ilsImagesSMALL        .Icons = ilsImagesLARGE        .ColumnHeaders.Add , , "Code", 1000, lvwColumnLeft        .ColumnHeaders.Add , , "Company", 2000, lvwColumnLeft        .ColumnHeaders.Add , , "Address", 1500, lvwColumnLeft        .ColumnHeaders.Add , , "Phone", 1500, lvwColumnRight    End WithEnd Function

By using the following procedure I can add data to the ListView:

VB Code:
Private Function AddItem(ByVal Code As String, ByVal Company As String, ByVal Address As String, ByVal Phone As String, ByVal Icon As String)Dim lvwNewItem      As ListItem    Set lvwNewItem = lvwData.ListItems.Add(, , Code, Icon, Icon)    With lvwNewItem        .SubItems(1) = Company        .SubItems(2) = Address        .SubItems(3) = Phone    End With    Set lvwNewItem = NothingEnd Function

I know that by using ListSubItems I can achieve the same thing:

VB Code:
Private Function AddItem(ByVal Code As String, ByVal Company As String, ByVal Address As String, ByVal Phone As String, ByVal Icon As String)Dim lvwNewItem      As ListItem    Set lvwNewItem = lvwData.ListItems.Add(, , Code, Icon, Icon)    With lvwNewItem        .ListSubItems.Add , , Company        .ListSubItems.Add , , Address        .ListSubItems.Add , , Phone    End With    Set lvwNewItem = NothingEnd Function

How would I add data to the ListView using the ColumnHeader's KEY? As with the above I have to have the code in the correct order otherwise data will be displayed in the wrong column...

Any ideas?

Listview Subitems As Checkboxes
I am loading some database info into a listview.
This includes four columns of ture or false boolean values.
Instead of displaying 'True' or 'False' in these subitem columns I would prefer to just have a checkbox.

Is this possible? I can't seem to find any info on this.

Cheers.

Adding Subitems To A Listview
I have 2 ADOR recordsets that Im using to get data from 2 tables in a database. The first recordsets data is to be the first column in the listview. The second recordset to be the subitem. I have tried adding to the listitems text & subitem but only get output of one row. Can anyone please help?

Checkboxes In Subitems Of A Listview....?
Checkboxes in subitems of a listview....?

I dont have the time or motivation to play with all of the lv style constants. mfc will do it in c++ no problem, Unfortunanly our companys pc's are locked down tighter than any straight mans ass in america, so installing an .ocx is out of the question. Has anyone played enough or possibly heard in some strange conversation of listviews if this is possible?

Listview And Subitems Question
Hello,

I would like to change the text color in a Listview control for all the lines that are Ghosted but the problem is that the text color is changed only in the first column and not for all SubItems.

Thanks for your help,

Thierry Demoy
France

VB6

Remove Subitems From Listview
Ok, i have a listview which the user populates with a bunch of data, licenses to be exact.
I then loop through the listview and compare SubItems(1) with a database. If that item
already exists in the database, i want to remove it from the listview. The listview has 5
columns like below, and i want to clear each row corresponding to SubItems(1), not the
entire listview. I guess i should use ListView1.ListItems.Remove(index), but i´m having
some problems coding the index part so that the item/row the loop is currently on is
deleted. I guess i need to declare an integer that keeps count of the lines processed by
the loop? Any suggestions to this?

itm.Text    itm.SubItems(1)    itm.SubItems(2)    itm.SubItems(3)    itm.SubItems(4)
Code:
For Each itm In Me.ListView1.ListItems
    objArs.QueryAddQualifier "Add on enabler", 1, itm.SubItems(1)
    objArs.QueryAddQualifier "Status", 1, "Permanent"
    objArs.QueryOpen
    If objArs.GetEntryCnt() > 0 Then
        List2.AddItem "Error! License " & itm.SubItems(1) & " already exists!"
        ' Code needed here to remove the row from ListView1
    End If
Next

Cheers!
Maverick



Edited by - Maverick2004 on 12/2/2004 6:06:11 AM

Getting The Values Of Listview Subitems
Hi

I'm very new to VB6 so apologies if this is an obvious question....

I have a listview that has 4 columns. The first column which has an index of 1 according to the property page, is hidden by having its width set to 0. When the user clicks on a row in the listview, I want to be able to get the values from each of the columns and assign them to variables. But I'm having trouble. Here's my code:

Code:Private Sub lvwAudit_ItemClick(ByVal Item As MSComctlLib.ListItem)
Dim ind As Integer
Dim itm As ListItem
ind = Item.Index
cmdEditAudit.Enabled = True
AuditInfoID = lvwAudit.ListItems(ind).SubItems(1)
AuditCheckDt = lvwAudit.ListItems(ind).SubItems(2)
AuditNxtChkDt = lvwAudit.ListItems(ind).SubItems(3)
AuditCmnts = lvwAudit.ListItems(ind).SubItems(4)
End Sub

When using this code, the "lvwAudit.ListItems(ind).SubItems(1)" bit gets the value from the second column and misses out the first entirely. The "lvwAudit.ListItems(ind).SubItems(4)" is an invalid property. I tried changing the 1 to 0 to get the value from the hidden column but it says that is an invalid property as well. It's like it ignores the existence of the hidden column altogether!

Please can anyone tell me where I'm going wrong? Thanks!

ListView Problems ; Can't Get Subitems In The Right Row
I've searched everywhere looking for tut's on listview can't find much...

Maybe someone can help.. Its probably something stupid I'm doing but I can't figure it out..
I'm tring to add items and subitems to a listview.. I'm assuming that the subitems(are like the next column)
I can get the first column right but as soon as I try and add a sub item in its spliting my first column to everyother one
and the same with the sub items.. Like:

12345
         abcde
678910
         fghijkl
202122

This isn't what I want... I need them like:

12345         abcde
67890         fghijk

Here's my code, I'm getting the data from an array & database
I must be doing something wrong here
Code:
    rsTblProd1.MoveFirst
    For i = 0 To UBound(arrDeleted)
        If arrDeleted(0) = "" Then
            Exit Sub
        End If
        rsTblProd1.Find "[Product Code]='" & arrDeleted(i) & "'"
        If rsTblProd1![Current Cost] = "0" Then
            sCost = "0.00"
        End If
        
        With frmResults.lvw
             .ListItems.Add , , rsTblProd1![Product Code]
             .ListItems.Add.ListSubItems.Add , , rsTblProd1![Description One]
         End With
    Next i

Thanks for any inputsuggestions
$hep



Edited by - $hep on 10/9/2004 7:35:24 PM

Backcolor Of Subitems In Listview
Hi all

How i can change the backcolor of a row (all subitems) in a listview?

ListView &gt; SubItems &gt; ForeColor
Hi, I've got a strange behaiver setting the ForeColor for SubItems in a ListView.
For some reason wich I can't seem to solve is, ones a SubItem is set to Blue it never goes back into a Black color.

Basically what I try to do is when selecting a row, set a certain SubItem ForeColor to Blue, and all other SubItems in the same column to Black.
But ones a SubItem is Blue, i can't seem to get it Black again.

Any suggestions?

Code:
' you need a ListView1 and Text1
Option Explicit

Private Sub Form_Load()

    ListView1.Arrange = lvwAutoTop
    ListView1.LabelEdit = lvwManual
    ListView1.View = lvwReport
    ListView1.FullRowSelect = True
    ListView1.ColumnHeaders.Add , , "Icon", 400
    ListView1.ColumnHeaders.Add , , "Unique ID", 1500
    ListView1.ColumnHeaders.Add , , "Title", 3000

    Dim i As Integer
    For i = 1 To 5
        ListView1.ListItems.Add , , "icon"
        ListView1.ListItems.Item(i).SubItems(1) = "uID " & i
        ListView1.ListItems.Item(i).SubItems(2) = "Title " & i
    Next i

End Sub

Private Sub ListView1_Click()

    Dim i As Integer
    For i = 1 To ListView1.ListItems.Count
            
            ' make all "Title" columns black
            ' both methods don't work ...
            ListView1.ListItems(i).ListSubItems(2).ForeColor = vbBlack
            ListView1.ListItems.Item(i).ListSubItems(2).ForeColor = vbBlack
            
    Next i
    
    Dim h As Integer
    h = ListView1.SelectedItem.Index
    
    ' set the selected "Title" column to Blue,
    ' this works, both methods ...
    ListView1.ListItems(h).ListSubItems(2).ForeColor = vbBlue
   'ListView1.ListItems.Item(h).ListSubItems(2).ForeColor = vbBlue
    
    Text1.Text = ListView1.ListItems(h).ListSubItems(2).Text
    Text1.SetFocus

End Sub




Edited by - T48 - [RedPlanet] on 9/13/2007 11:19:59 AM

How To Edit ListView SubItems In VB6
Hi,
I can edit ListView item but not the SubItems. Anyone got any sample code to edit ListView SubItems?
Thank you.
Rgds,
Gilroy.

Listview Labeledit Subitems?
Does anyone have a method to perform a label edit on listview *subitems* - that would be great.

M.

Editing Subitems In Listview
Hi there !
I want to edit subitems in listview.
I click on the listview but the only thing i can edit is the parent column.
I also do not want the parent column to be editable.

Thank you !

ListView With Checkboxes As SubItems
I have scoured the Internet and MSDN, maybe I'm blind, but I can't find anything that tells me how to make checkboxes in my ListView subitems. I know that you can have a checkbox beside the item but that is not what I am looking for. I need checkboxes as subitem data. How can I make that happen?

Thanks.

Adding Pictureboxes To The Subitems Of A Listview
Hello, I'd like to add pictureboxes to the subitems of a Listview, so I can use them as a progressbar.

I can probably use SetParent to add pictureboxes to the Listview, but I have no idea how to keep the pictureboxes on the correct position when items are removed or the Listview is sorted.

Does anybody know how to do this?

Merge ListView Items &amp; Subitems
I have LV1 with data and LV2 with updated data. I would like to delete the data in LV2 if it's the same in LV1. For the data to match and be deleted the items and subitems must match. Once the doubles are deleted I can just add to LV1.

The only problem is the deletion of doubles. Any help is greately appreciated.

Silver

Adding Icons To Subitems Of A Listview
Hi everyone!

I've tried searching in past threads to do this but failed. In my project, I use a listview with 4 columns and to fill it, I use recordsets from a table in the project's database. What I want to do is to add icons to certains rows in the listview and the icons are to be displayed in the 4th column of the listview. I really hope it can possibly be done.

Thanks a lot in advance for any help from any one of you.

Error 380 Using Listview Subitems Property
I am completely at a loss as to why this happens, but I have a small table that keeps track of reports. The information in this table is then displayed for the end-user, thus allowing them to choose a report from the list and view it. I filter by either unviewed reports only, or all reports. The problem is, when I try to list all unviewed reports, I get an error 380 "invalid Property value" when setting the subitems(i) = to something in the table. I can't say for sure, but it only seems to happen if the date viewed is empty. Even if I haven't got that far in the code!

Code:
Set rsReports = db.OpenRecordset(strSQL)
'Fill the listbox with the reports that have NOT been viewed
Do Until rsReports.EOF
If Not IsNull(rsReports![FILE]) Then
Set ItemX = lsvReports.ListItems.Add(, , rsReports![FILE])
If Not IsNull(rsReports![Date]) Then
ItemX.SubItems(conRptDate) = rsReports![Date]
Else
'The Date Should never be Null
ItemX.SubItems(conRptDate) = FileDateTime(ItemX)
End If
If Not IsNull(rsReports![Viewed]) Then ItemX.SubItems(conViewed) = rsReports![Viewed]
If Not IsNull(rsReports![From]) Then ItemX.SubItems(conSenderID) = rsReports![From]
If Not IsNull(rsReports![SORTDATE]) Then ItemX.SubItems(conRptSortDate) = rsReports![SORTDATE]
If Not IsNull(rsReports![SORTVIEW]) Then ItemX.SubItems(conRptSortViewed) = rsReports![SORTVIEW]
If Not IsNull(rsReports![BATCH]) Then ItemX.SubItems(conClaimsBatch) = rsReports![BATCH]
End If
rsReports.MoveNext
Loop
It crashes out when I try to assign the date (a non-empty field) I have tried other orders as well, and it does not matter which item is first. The conRptDate is a constant = 1 conViewed = 2 etc.
Thanks in advance for any help!

Edit A Listview SubItems With A Combobox?
I want to edit a subItems in my listview with a combo box, so I can change the value of the subItems with some of the values in the combobox? Is that possible?

ForeColor Property For ListView SubItems?
I have a ListView control in Report form. The list contains a list of hazards in our facility and several SubItems providing details of the Hazard. Each hazard can be listed as Minor, Moderate, or Severe. I want the entire row to be texted Red if the Hazard is Severe. Using the following code, I have gotten the Index to show up Red, but can't get any of the SubItems to go Red. Is there a way to do this?

Set NewItem = lvMain.ListItems.Add(, , adoRS("Index"))
.
.
.
NewItem.SubItems(4) = adoRS("Severity")
If adoRS("Severity") = "Severe" Then
NewItem.ForeColor = vbRed
End If

where adoRS is a RecordSet for the database containing the data and lvMain is the ListView control.

Thanks ahead of time for any and all assistance.

Changing The Color Of Subitems In A Listview
hiya guys, long time no see,

I'm trying to use some code I found to change the subitems backcolor and textcolor in a listview...

at the mo it changes the colors of the entire row no prob, but i've searched high and low and cant figure out how to change individual subitems...

here;s the code: (NOTE: The meaty bit is at the bottom!)

<vbcode>' bas module code
' Hook system and color the backcolor of listview rows different colors
' as with hooking if you unload using the stop button of Visual Basic
' and you don't use the unloadquerry (the X on the form)
' then windows will crash
'
Option Explicit

Public Const GWL_EXSTYLE = -20
Public Const GWL_HINSTANCE = -6
Public Const GWL_HWNDPARENT = -8
Public Const GWL_ID = -12
Public Const GWL_STYLE = -16
Public Const GWL_USERDATA = -21
Public Const GWL_WNDPROC = -4
Public Const DWL_DLGPROC = 4
Public Const DWL_MSGRESULT = 0
Public Const DWL_USER = 8

Public Const NM_CUSTOMDRAW = (-12&)
Public Const WM_NOTIFY As Long = &H4E&
Public Const CDDS_PREPAINT As Long = &H1&
Public Const CDDS_SUBITEM = &H20000
Public Const CDRF_NOTIFYITEMDRAW As Long = &H20&
Public Const CDRF_NOTIFYSUBITEMDRAW = &H20 '// flags are the same, we can distinguish by context
Public Const CDDS_ITEM As Long = &H10000
Public Const CDDS_ITEMPREPAINT As Long = CDDS_ITEM Or CDDS_PREPAINT
Public Const CDRF_NEWFONT As Long = &H2&

Public Type NMHDR
hWndFrom As Long ' Window handle of control sending message
idFrom As Long ' Identifier of control sending message
code As Long ' Specifies the notification code
End Type

' sub struct of the NMCUSTOMDRAW struct
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

' generic customdraw struct
Public Type NMCUSTOMDRAW
hdr As NMHDR
dwDrawStage As Long
hDC As Long
rc As RECT
dwItemSpec As Long
uItemState As Long
lItemlParam As Long
End Type

' listview specific customdraw struct
Public Type NMLVCUSTOMDRAW
nmcd As NMCUSTOMDRAW
clrText As Long
clrTextBk As Long
' if IE >= 4.0 this member of the struct can be used
iSubItem As Integer
End Type

Public Type TwoLongs
lngForeColor As Long
lngBackColor As Long
End Type


Public g_addProcOld As Long
Public g_MaxItems As Long
Public clr() As TwoLongs


Public Declare Function SetWindowLong Lib "user32.dll" Alias _
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long


Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)

Public Declare Function CallWindowProc Lib "user32.dll" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long

Public Function WindowProc(ByVal hWnd As Long, _
ByVal iMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long

Select Case iMsg
Case WM_NOTIFY
Dim udtNMHDR As NMHDR
CopyMemory udtNMHDR, ByVal lParam, 12&

With udtNMHDR
If .code = NM_CUSTOMDRAW Then
Dim udtNMLVCUSTOMDRAW As NMLVCUSTOMDRAW
CopyMemory udtNMLVCUSTOMDRAW, ByVal lParam, Len(udtNMLVCUSTOMDRAW)
With udtNMLVCUSTOMDRAW.nmcd
Select Case .dwDrawStage
Case CDDS_PREPAINT
WindowProc = CDRF_NOTIFYITEMDRAW
Exit Function
Case CDDS_ITEMPREPAINT
WindowProc = CDRF_NOTIFYSUBITEMDRAW
Exit Function
Case (CDDS_ITEMPREPAINT Or CDDS_SUBITEM)
'FORECOLOR
If clr(.dwItemSpec).lngForeColor <> 0 Then
udtNMLVCUSTOMDRAW.clrText = clr(.dwItemSpec).lngForeColor
' udtNMLVCUSTOMDRAW.iSubItem = 2
CopyMemory ByVal lParam, udtNMLVCUSTOMDRAW, Len(udtNMLVCUSTOMDRAW)
End If
'BACKCOLOR
If clr(.dwItemSpec).lngBackColor <> 0 Then
udtNMLVCUSTOMDRAW.clrTextBk = clr(.dwItemSpec).lngBackColor
' udtNMLVCUSTOMDRAW.iSubItem = 2
CopyMemory ByVal lParam, udtNMLVCUSTOMDRAW, Len(udtNMLVCUSTOMDRAW)
End If
WindowProc = CDRF_NEWFONT
Exit Function
End Select
End With
End If
End With
End Select
WindowProc = CallWindowProc(g_addProcOld, hWnd, iMsg, wParam, lParam)
End Function

Public Sub SetLIBackColor(lv As ListView, nitem As Integer, BkColor As Long)
clr(nitem - 1).lngBackColor = BkColor
lv.Refresh
End Sub

Public Sub SetLIForeColor(lv As ListView, nitem As Integer, ForeColor As Long)
clr(nitem - 1).lngForeColor = ForeColor
lv.Refresh
End Sub
</vbcode>

Foreground Color In Listview Subitems
Does anyone know how to change the foreground color in a listview subitems. I can change the colors of the first column, but none of the subitems.

Adding Listview Subitems With Function??
Ok, here's what I'm trying to do. When you click a button in my program the Listview is populated with mp3 files. I have a function to reader the header of the mp3. So here's what I'm trying to do.

Listview1.listitems(i).listsubitems.add , , Mp3info.Bitrate

I want the second column in my listview to be populated with the bitrate by calling the function MP3info, which is in a module in my program.

I need it to get the bitrate of all of my listitems in the listview (column 1), and then let my listsubitems = the bitrate the functionn Mp3info.bitrate returns.

How would I need to arrange my code? Any help is appreciated.

Thanks

-Jeremy

How Do I Read Subitems When Looping In A Listview??
Can someone show me an example code of how to loop through all of the items in a listview including the subitems? I got the items but do not know how to read the subitems without selecting them with the mouse first.

I did this so far:

For i = 1 To listview1.ListItems.Count
MsgBox listview1.ListItems.Item(i)
Next


How do I get the subitems for each listitem as I loop above? I need to assign them to string variables.

Thanks for your help!!!

Copyright © 2005-08 www.BigResource.com, All rights reserved