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:
'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
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