-
List View Checkmarks
Hi All,
I have the following Code ...
<Serializable()> Public Structure sLV
Public lvi As ListViewItem
End Structure
Dim LV As sLV
Dim rLV As sLV
Dim LI as ListViewItem
I have a Single Listview on the Form : ListView1 in Details Mode and Checkmarks Enabled
Public Sub MakeLV
ListView1.Clear()
ListView1.CheckBoxes = True
ListView1.Columns.Add("ONE", ListView1.Width)
Dim LI As New ListViewItem()
LI.Checked = True
LV.lvi = LI.Clone
ListView1.Items.Add(LI)
End Sub
The code Loads the ListView and Structure with a DATA Item
Save Function
Public Sub SystemSave(ByVal strFname As String)
' Save the Object to a DISK File
Dim myFS As Stream = File.Create(strFname) ' Open File Stream
Dim serializer As New BinaryFormatter() ' Create Serializer
serializer.Serialize(myFS, LV) ' Serialize the Object
myFS.Close()
End Sub
' Restore Function
Public Sub SystemRestore(ByVal strFname As String)
' Restore Object from Disk File
Dim myFS As Stream = File.OpenRead(strFname) ' Open File Stream
Dim deserializer As New BinaryFormatter()
rLV = CType(deserializer.Deserialize(myFS), sLV)
myFS.Close()
End Sub
Now I Serialize the Structure and Store to Disk, Then Retreive the Structure and try to Restore the Item in the ListView
Public Sub RestoreLV
ListView1.Clear()
ListView1.CheckBoxes = True
ListView1.Columns.Add("ONE", ListView1.Width)
Dim LI As New ListViewItem()
LI = rLV.lvi.Clone
ListView1.Items.Add(LI)
End Sub
It does restore the Item BUT NOT the CheckMark if it was checked ? Does anybody know why this would happen ?
Nick
-
because the default value for the checkbox is false so you have to "remember" for the program(use an array variable) which checkbox's were checked then set li.checkbox.checked = true
-
Thanks JYM :)
Thank for your help Jym. I actually did it all the hard way to begin with I acutally made a Structure which carried the Checkmark state and that did the trick. I just figured I was doing something wrong. I assumed that when you CLONE and object it is an EXACT copy of the original including the checkmark. It is ashame that it doesn't work that way.
Thanks Again