Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim i As Integer
Dim lvitem As ListViewItem
For i = 1 To 5
lvitem = ListView1.Items.Add("1")
lvitem.SubItems.Add("sonia")

Next
End Sub

Above code add the five items in a listview with checboxes before each item.
When we run the form,all Checkboxes are unchecked.I want that by default all checkboxes are checked...
Ur help will be highly appreciated!!!!!!

Recommended Answers

All 3 Replies

Private Sub ListView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Dim i As Integer
        Dim lvitem As ListViewItem
        For i = 1 To 5
            lvitem = ListView1.Items.Add("1")
            lvitem.SubItems.Add("sonia")
            lvitem.Checked = True
        Next 
End Sub
commented: worked +1

hey,thx . I want to save the checked items into the textfile--
But with my code all the items are written in textFile.I m posting my code as follows-
Plz go thru it.

On Button2 click,I want that items that are checked are saved into the textfile.
Call SaveTextToFile is the procedure that saves the records into the textfile. I know that procedure dats y not pasting.
Plz just tell me that to procedure SaceTextToFile only that records are passed dat are checked.


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim checkedItems As ListView.CheckedListViewItemCollection = ListView1.CheckedItems
Dim lvitem As ListViewItem
Dim lcount As Integer


For Each lvitem In checkedItems

For lcount = 0 To ListView1.Items.Count - 1
Call SaveTextToFile(ListView1.Items(lcount).SubItems(0).Text, ListView1.Items(lcount).SubItems(1).Text)
Next
Next

End Sub

I do it myself. Thx for the help/.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.