Results 1 to 1 of 1

Thread: Fuction 4 Adding Items 2 ListView

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    75

    Fuction 4 Adding Items 2 ListView

    This is my 1st codebank entry... i was trying to find just a nice easy way 2 add to my logs... so i created this function... that adds 3 items 2 a listview... also it uses time as the second item 2 add... but you can easily change that

    hope this helps someone ... i know if i had it yesterday it would have saved me 2 hrs... ... also im a pretty big newb... if theres a better way 2 do this please share


    vb.net Code:
    1. 'By ahostbr VBForums.com
    2.     'Usage:
    3.     'to_log("HI", 0, "Very Nice Function :)")
    4.     'im using time 4 item 2... you can change that if youd like :)
    5.     Public Function to_log(ByVal item1_string As String, ByVal img_index As Integer, ByVal item3 As String)
    6.         'The string to pass is The 1st Items String &_
    7.         ' Integer to Pass is Image Index
    8.         Dim item1 As New ListViewItem(item1_string, img_index)
    9.  
    10.         'Enabled Images
    11.         item1.Checked = True
    12.  
    13.         ' Grabs The Time
    14.         Dim time As String = TimeOfDay.Now.ToString
    15.  
    16.         'Adds To Second Column
    17.         item1.SubItems.Add(time) 'using time here, you can just add whatever                
    18.  
    19.         'Adds To 3rd Column
    20.         item1.SubItems.Add(item3)
    21.  
    22.         ' Create ImageList objects.
    23.         Dim imageList As New ImageList()
    24.         ' Initialize the ImageList objects from my.resources.
    25.         imageList.Images.Add(My.Resources.black_check) 'index is 0
    26.         imageList.Images.Add(My.Resources.question_mark) 'index is 1
    27.         imageList.Images.Add(My.Resources.err_blood) 'index is 2
    28.  
    29.         'Assign the ImageList objects to the ListView.
    30.         ListView1.LargeImageList = imageList
    31.         ListView1.SmallImageList = imageList
    32.  
    33.         'Adds What We Made Maybe Called after a Next Statement
    34.         ListView1.Items.AddRange(New ListViewItem() {item1})
    35.  
    36.  
    37.         Return Nothing
    38.     End Function

    Copy Friendly:
    Code:
        'By ahostbr VBForums.com
        'Usage:
        'to_log("HI", 0, "Very Nice Function :)")
        'im using time 4 item 2... you can change that if youd like :)
        Public Function to_log(ByVal item1_string As String, ByVal img_index As Integer, ByVal item3 As String)
            'The string to pass is The 1st Items String &_
            ' Integer to Pass is Image Index
            Dim item1 As New ListViewItem(item1_string, img_index)
    
            'Enabled Images
            item1.Checked = True
    
            ' Grabs The Time
            Dim time As String = TimeOfDay.Now.ToString
    
            'Adds To Second Column
            item1.SubItems.Add(time) 'using time here, you can just add whatever                
    
            'Adds To 3rd Column
            item1.SubItems.Add(item3)
    
            ' Create ImageList objects.
            Dim imageList As New ImageList()
            ' Initialize the ImageList objects from my.resources.
            imageList.Images.Add(My.Resources.black_check) 'index is 0
            imageList.Images.Add(My.Resources.question_mark) 'index is 1
            imageList.Images.Add(My.Resources.err_blood) 'index is 2
    
            'Assign the ImageList objects to the ListView.
            ListView1.LargeImageList = imageList
            ListView1.SmallImageList = imageList
    
            'Adds What We Made Maybe Called after a Next Statement
            ListView1.Items.AddRange(New ListViewItem() {item1})
    
    
            Return Nothing
        End Function
    Last edited by ahostbr; Dec 20th, 2008 at 08:18 PM.
    How To Make A Youtube Downloader
    I use Visual Studio 2008 Pro...

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