Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - .NET

Страница: 1 |

 

  Вопрос: ListView item - картинка, subitem - картинка. Как? Добавлено: 18.05.06 11:01  

Автор вопроса:  Elfebet
Нужна в listiview запихнуть 2 картинки. listiview должен быть в стиле this.listView1.View = View.Details;.
Так вот, картинку в listview1.items кинуть можна, а надо еще картинку добавить в listview1.items.SubItems. как добавить картинку в SubItems ума не приложу, я видел что такое возможно, но как это сделать подскажите плиз? (желательно с примером)

Ответить

  Ответы Всего ответов: 1  

Номер ответа: 1
Автор ответа:
 SRV



ICQ: 254226129 

Вопросов: 30
Ответов: 107
 Профиль | | #1 Добавлено: 18.05.06 11:40
Option Explicit
Private Sub Form_Load()
    ' build our column headers
    With lstListView.ColumnHeaders
        .Add , , "", 400, , "S"
        .Add , , "", 400, , "Flag"
        .Add , , "", 400, , "Clip"
        .Add , , "", 400, , "A"
        .Add , , "", 400, , "Bolt"
        .Add , , "Subject", 3000
        .Add , , ";Date", 1000, , ";Down"
        .Add , , "Time", 1000
        .Add , , "Size", 1000
        
    End With
    
    ' set the default sort to the date column
    lstListView.Sorted = True
    lstListView.SortOrder = lvwAscending
    lstListView.SortKey = 5
    
    ' just to show this off
    LoadList
    
End Sub

Private Sub Form_Resize()
    
    ' ignore resize errors
    On Error Resume Next
    
    ' resize the listview
    lstListView.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
    
End Sub

Private Sub lstListView_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    
    ' make sure the list has sorting enabled
    lstListView.Sorted = True
    
    If lstListView.SortOrder = lvwAscending Then
        ' if it's currently asc then desc it
        lstListView.SortOrder = lvwDescending
    Else
        ' if it's currently desc then asc it
        lstListView.SortOrder = lvwAscending
    End If
    
    ' only change the icon if there isn't one there
    ' or it's an arrow
    If lstListView.ColumnHeaders(ColumnHeader.Index).Icon = 0 Or _
    lstListView.ColumnHeaders(ColumnHeader.Index).Icon = "Up" Then
        lstListView.ColumnHeaders(ColumnHeader.Index).Icon = ";Down"
        GoTo ClearAllOthers
    End If
    
    ' only change the icon if there isn't one there
    ' or it's an arrow
    If lstListView.ColumnHeaders(ColumnHeader.Index).Icon = 0 Or _
    lstListView.ColumnHeaders(ColumnHeader.Index).Icon = ";Down" Then
        lstListView.ColumnHeaders(ColumnHeader.Index).Icon = "Up"
        GoTo ClearAllOthers
    End If
    
ClearAllOthers:
    ' setup a counter variable
    ;Dim lngIndex As Long
    
    ' loop through all of the column headers
    For lngIndex = 1 To lstListView.ColumnHeaders.Count - 1
        ' except the current one
        If lngIndex <> ColumnHeader.Index Then
            ' and if it has an 'up' or 'down' then
            If lstListView.ColumnHeaders(lngIndex).Icon = "Up" Or _
            lstListView.ColumnHeaders(lngIndex).Icon = ";Down" Then
                ' dectroy it's icon
                lstListView.ColumnHeaders(lngIndex).Icon = 0
            End If
        End If
    Next lngIndex
    
End Sub

Private Sub LoadList()
    
    ' add some junk items to the list
    ' see function 'AddToListView' for the details
    AddToListView "Re: Feliz Navidad", "22/12/99", "0:18", "8K", False, True
    AddToListView "Feliz Navidad", "20/12/99", "13:02", "263K", True, False, True
    AddToListView "Feliz Navid...aggggg", "13/12/99", "22:02", "28K", True
    AddToListView "Re; web", "19/11/99", "18:38", "5K", True
    AddToListView "Rases de datos de liber-Swiss", "05/05/99", "9:59", "865K", True, True
    AddToListView "Re; Boomerang... Contestacion", "02/04/99", "11:16", "5K", True
    AddToListView "RV:", "12/03/99", "2:41", "676K", True, True
    AddToListView "RV: Esto es BUENISIMO...!!!", "27/02/99", "9:24", "3K", True
    
    ' refresh the lsitview and select the first item
    lstListView.Refresh
    lstListView.ListItems.Item(1).Selected = True
    
End Sub

Private Function AddToListView(strSubject As String, _
                               strDate As String, _
                               strTime As String, _
                               strSize As String, _
                               Optional bolMailRead As Boolean, _
                               Optional bolPaperClip As Boolean, _
                               Optional bolShowR As Boolean)
    
    ' Note: i did not handle the second (flag) and fifth (bolt) columns
    ' because the image you sent sisn't have them in it. But I'm sure
    ' that from this code you can figure it out easily.
    
    ' setup a variable to use to build an item
    ;Dim lstEntry As ListItem
    
    ' set the icon to the first item
    If bolMailRead = True Then
        Set lstEntry = lstListView.ListItems.Add(, , " ", "Mail_Read";)
    Else
        Set lstEntry = lstListView.ListItems.Add(, , " ", "Mail_New";)
    End If
    
    ' build the first two children
    lstEntry.SubItems(1) = ""
    lstEntry.SubItems(2) = ""
    
    ' if we wanted a 'clip' then set the clip
    If bolPaperClip = True Then lstEntry.ListSubItems.Item(2).ReportIcon = "Clip"
    
    ' build another blank child
    lstEntry.SubItems(3) = ""
    
    ' if we wanted an 'r' then set the r
    If bolShowR = True Then lstEntry.ListSubItems.Item(3).ReportIcon = "R"
    
    ' build another blank child
    lstEntry.SubItems(4) = ""
    
    ' set the items to teh desired values
    lstEntry.SubItems(5) = strSubject
    lstEntry.SubItems(6) = strDate
    lstEntry.SubItems(7) = strTime
    lstEntry.SubItems(8) = strSize
    
End Function

Это пример с сайта http://www.Planet-Source-Code.com очень даже неплохой пример :)

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам