How to change listbox to listview???
Dim intIDX As Integer
Dim ServerList As ListOfServer
' Set MousePointer to Working Pointer
MousePointer = vbHourglass
' Clear the ListBox
lstComputers.Clear
' Get List of Computers on Network (Type All: Server and Workstation)
ServerList = EnumServer(SRV_TYPE_ALL)
' Loop through all the computers and add them to the listbox
If ServerList.Init Then
For intIDX = 1 To UBound(ServerList.List)
lstComputers.AddItem ServerList.List(intIDX).ServerName
Next
End If
1stComputer is the name of the listbox.How do i change the display to listview in order for me to change the colour of the item in it. I can display it in treeview but all the function such as right click pop up menu can't work. Please help....
1 Attachment(s)
Re: How to change listbox to listview???
Here is an example of how to use a listview, but coloring a row will be difficult.
Re: How to change listbox to listview???
VB Code:
Public Sub ColorListviewRow(lv As ListView, ByVal RowNbr As Long, ByVal RowColor As OLE_COLOR)
'***************************************************************************
'Purpose: Color a ListView Row
'Inputs : lv - The ListView
' RowNbr - The index of the row to be colored
' RowColor - The color to color it
'Outputs: None
'***************************************************************************
Dim itmX As ListItem
Dim lvSI As ListSubItem
Dim intIndex As Integer
On Error GoTo ErrorRoutine
Set itmX = lv.ListItems(RowNbr)
itmX.ForeColor = RowColor
For intIndex = 1 To lv.ColumnHeaders.Count - 1
Set lvSI = itmX.ListSubItems(intIndex)
lvSI.ForeColor = RowColor
Next
Set itmX = Nothing
Set lvSI = Nothing
Exit Sub
End Sub
not made by me
useage:
VB Code:
ColorListviewRow ListView1, Index, Color
Re: How to change listbox to listview???
OK, that's the ForeColor and I assumed that tauhu82 was asking about the BackColor.
Re: How to change listbox to listview???
Sorry to hijack someone's thread, but when I tried to do this, I get a compile error with user defined type not defined error with the Public Sub line highlighted.
Re: How to change listbox to listview???
Do you have OLE_COLOR declared?
Re: How to change listbox to listview???
No Hack. I don't know what it is or how to declare it.
Re: How to change listbox to listview???
Quote:
Originally Posted by Supremus
No Hack. I don't know what it is or how to declare it.
Then that is the user defined type it doesn't know.
Hold on, I know I have it somewhere.
Re: How to change listbox to listview???
I'm wrong. OLE_COLOR is actually a valid type. (I have no clue why I thought it was a UDT :confused: )
Ok, then the only other thing it could be (if it is blowing up on the Public Sub line) is the ListView.
Do you have a ListView control on your form?
Re: How to change listbox to listview???
I was just looking for that. No and I don't think I have the component to add it. I was just having a look at Martin's project.zip above.
Re: How to change listbox to listview???
Oh. Ok. I have found it - looking in the wrong place. Do I replace the list box with the listview?
I have added a listview and I still get the same error.
Re: How to change listbox to listview???
:confused: You have a listview on your form, and you get this error
Quote:
Originally Posted by Supremus
I get a compile error with user defined type not defined error
on this line
VB Code:
Public Sub ColorListviewRow(lv As ListView, ByVal RowNbr As Long, ByVal RowColor As OLE_COLOR)
???
If so, that makes no sense. If you have a Listview on your form, that takes care of the first type....both a Long and OLE_COLOR are built in VB types.
Re: How to change listbox to listview???
Hmmm. Something funny going on. I just created a new project and it compiled ok. I'll get back to my form and do some checking.
Thanks for your time.
Re: How to change listbox to listview???
Quote:
Originally Posted by Supremus
Hmmm. Something funny going on. I just created a new project and it compiled ok. I'll get back to my form and do some checking.
Thanks for your time.
You might have a corrupt .vbp file that isn't picking up all of the standard references that are built into VB.
Try this:
Open up a new, standarrd exe, project. Remove the default Form1.
Add each form and module from your old project to this new project and run it. If the whole thing works, then your .vbp file was the problem. If so, just do a SaveAs on the project file, and overlay the old .vbp file.
(Incidentially, you would need to add any components or references to the new project file that the old one had as well as the forms and modules.)