CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002
    Location
    USA
    Posts
    207

    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

  2. #2
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    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

  3. #3
    Join Date
    Dec 2002
    Location
    USA
    Posts
    207

    Smile 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

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

Featured