Results 1 to 15 of 15

Thread: How to change listbox to listview???

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation 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....

  2. #2

  3. #3
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: How to change listbox to listview???

    VB Code:
    1. Public Sub ColorListviewRow(lv As ListView, ByVal RowNbr As Long, ByVal RowColor As OLE_COLOR)
    2. '***************************************************************************
    3. 'Purpose: Color a ListView Row
    4. 'Inputs : lv - The ListView
    5. '         RowNbr - The index of the row to be colored
    6. '         RowColor - The color to color it
    7. 'Outputs: None
    8. '***************************************************************************
    9.    
    10.     Dim itmX As ListItem
    11.     Dim lvSI As ListSubItem
    12.     Dim intIndex As Integer
    13.    
    14.     On Error GoTo ErrorRoutine
    15.    
    16.     Set itmX = lv.ListItems(RowNbr)
    17.     itmX.ForeColor = RowColor
    18.     For intIndex = 1 To lv.ColumnHeaders.Count - 1
    19.         Set lvSI = itmX.ListSubItems(intIndex)
    20.         lvSI.ForeColor = RowColor
    21.     Next
    22.  
    23.     Set itmX = Nothing
    24.     Set lvSI = Nothing
    25.    
    26.     Exit Sub
    27. End Sub
    not made by me


    useage:
    VB Code:
    1. ColorListviewRow ListView1, Index, Color

  4. #4

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Talking Thanks alot you guys!!!

    Thanks alot for helping me. Yes i'm looking for the forecolor because i have to differentiate each different computer. I will try the suggestions you all gave me. Post agin the result after i have try it ok.

    Thank you so very much..... to All....

  6. #6
    Hyperactive Member
    Join Date
    Feb 2005
    Location
    Wollongong. NSW. Australia
    Posts
    470

    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.
    My reputation is in tatters. Don't bother trying to repair it.

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

    Re: How to change listbox to listview???

    Do you have OLE_COLOR declared?

  8. #8
    Hyperactive Member
    Join Date
    Feb 2005
    Location
    Wollongong. NSW. Australia
    Posts
    470

    Re: How to change listbox to listview???

    No Hack. I don't know what it is or how to declare it.
    My reputation is in tatters. Don't bother trying to repair it.

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

    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.

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

    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 )

    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?

  11. #11
    Hyperactive Member
    Join Date
    Feb 2005
    Location
    Wollongong. NSW. Australia
    Posts
    470

    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.
    My reputation is in tatters. Don't bother trying to repair it.

  12. #12
    Hyperactive Member
    Join Date
    Feb 2005
    Location
    Wollongong. NSW. Australia
    Posts
    470

    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.
    Last edited by Supremus; Apr 6th, 2006 at 08:08 AM.
    My reputation is in tatters. Don't bother trying to repair it.

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

    Re: How to change listbox to listview???

    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:
    1. 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.

  14. #14
    Hyperactive Member
    Join Date
    Feb 2005
    Location
    Wollongong. NSW. Australia
    Posts
    470

    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.
    My reputation is in tatters. Don't bother trying to repair it.

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

    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.)

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