CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: List view

  1. #1
    Join Date
    Apr 2002
    Location
    USA
    Posts
    34

    List view

    Can anybody send me the code to add both the icon and text into the listview control so that it can be viewed as exactly as its in the Yahoo messenger with the group and friends under it with icons along with them
    Thanks in advance
    Smitha

    smitha_verghese@yahoo.com

  2. #2
    Join Date
    Sep 2000
    Posts
    77

    Re: List view


    I don't think Yahoo messanger is using a ListView control, i guess it's using a treeview control.

    Any way, here is how to add an Item to List view control.

    Dim LVItem As ListItem

    Set LVItem = fMainForm.lvListView.ListItems.Add
    LVItem.Text = "Your text"
    LVItem.SmallIcon = 1

    An ImageList control should have already been assigned to lvListView.

    Hope this helps.

    -kiran.


  3. #3
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792

    Re: List view

    The following code fills the listbox. You also have to go into the properties of the listbox and associate the icon with an image from your imagelist. Make sure the "view" property of the listbox is set to "3-lvwReport".

    Especially, look in the code for the line beginning "set itmX = " to determine how to set the icon (in this case we've named the icon "mksExistingIcon", which is what we've named it in the imagelist.)

    public Sub FillListView(byval lstView as ListView, byval nListType as Integer)

    Dim i, j, iMax, iMaxFields as Integer
    Dim strSql as string

    Dim colX as ColumnHeader
    Dim intX as Integer ' Counter variable.
    Dim itmX as ListItem 'Temp var to hold info for listview

    Dim itemtext() as string
    Dim strFldName as string

    Dim strColHead() as string


    Dim sSql as string
    Dim sParams as string
    Dim rs as ADODB.Recordset



    Select Case nListType
    Case 0 'Params
    iMax = 3
    ReDim strColHead(iMax + 1) ' 1 based...not zero based
    ReDim itemtext(iMax) ' Zero based
    sSql = "p_view_background_task_param"
    sParams = "'" & strTask & "', '" & strDateFrom & "'"
    With lstView
    .ColumnHeaders.Clear
    .ListItems.Clear
    .GridLines = true
    strColHead(1) = "Submitted date"
    strColHead(2) = "Task Name"
    strColHead(3) = "Parameter Type"
    strColHead(4) = "Parameter Value"
    .ColumnHeaders.ADD , , strColHead(1), .Width / 3
    .ColumnHeaders.ADD , , strColHead(2), .Width / 4
    .ColumnHeaders.ADD , , strColHead(3), .Width / 5
    .ColumnHeaders.ADD , , strColHead(4), .Width / 5
    End With

    end select

    set rs = goDataAccess.ExecuteCommand(sSql, true, sParams, adCmdStoredProc)


    ' Fill the listview control
    While Not rs.EOF
    If Not IsNull(rs.Fields(0).Value) then
    itemtext(0) = rs.Fields(0).Value
    else
    itemtext(0) = ""
    End If
    set itmX = lstView.ListItems.ADD(, "ITEM" & rs.AbsolutePosition, itemtext(0), , mksExistingIcon)
    for i = 1 to iMax
    If Not IsNull(rs.Fields(i).Value) then
    itemtext(i) = rs.Fields(i).Value
    itmX.SubItems(i) = itemtext(i)
    next i
    End If
    rs.MoveNext
    Wend

    rs.Close
    set rs = nothing




    Niall Baird
    Director
    VB Web Solutions Pty Ltd
    Victoria, Australia
    Be nice to Harley riders...

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

Featured