vb 2005 and simple way to wright listview and all its propities to file

J

John

Hi not sure were to post this but would appreciate if someone knows
simple answer...... which usually never exists



hi have added all my items subitmes and colors etc to my listview1 in
vb 2005


is there a simple way to save the whole object to file
instead of iterating though each property


such as


Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing


FileSystem.FileOpen(1, "j:\test\lvobj.txt", OpenMode.Output,
OpenAccess.Write, OpenShare.Shared)

Write(1, obj.ToString)

FileClose(1)

End Sub


then read it in at program start

dim the file as a listview1
and it would have all my items and subitems and colors, you know
something simple



PS isn't there something magical like saveobj(.....................)
I know i'm dreaming

thanks in advance
 
R

rowe_newsgroups

Hi not sure were to post this but would appreciate if someone knows
simple answer...... which usually never exists

hi have added all my items subitmes and colors etc to my listview1 in
vb 2005

is there a simple way to save the whole object to file
instead of iterating though each property

such as

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

FileSystem.FileOpen(1, "j:\test\lvobj.txt", OpenMode.Output,
OpenAccess.Write, OpenShare.Shared)

Write(1, obj.ToString)

FileClose(1)

End Sub

then read it in at program start

dim the file as a listview1
and it would have all my items and subitems and colors, you know
something simple

PS isn't there something magical like saveobj(.....................)
I know i'm dreaming

thanks in advance

I'm not sure if the listview is serializable or not, but if it is you
can just serialize it to xml or a few different formats. You should be
able to find some serialization examples on google or in the ng
archives, just try to adapt those to the listview. If the listview
cannot be serialized, than you might be able to just save the
datasource to a file and restore the listview from there. Datasets and
datatables expose a SaveXml() and LoadXml() method that you can use
for this.

Thanks,

Seth Rowe [MVP]
 
K

kimiraikkonen

Hi not sure were to post this but would appreciate if someone knows
simple answer...... which usually never exists

hi have added all my items subitmes and colors etc to my listview1 in
vb 2005

is there a simple way to save the whole object to file
instead of iterating though each property

such as

  Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        FileSystem.FileOpen(1, "j:\test\lvobj.txt", OpenMode.Output,
OpenAccess.Write, OpenShare.Shared)

 Write(1, obj.ToString)

        FileClose(1)

    End Sub

then    read it  in at program start

dim  the file  as a  listview1
 and it would have all my items and subitems and colors, you know
something simple

PS isn't there something magical  like saveobj(.....................)
I know i'm dreaming

thanks in advance

Hi,
I'm not familiar with listview at the moment, but here is a code that
saves all the items of a "listbox" into a text file:

Dim myArray(Me.ListBox1.Items.Count - 1) As Object
Me.ListBox1.Items.CopyTo(myArray, 0)
Dim Data As String = Join(myArray, Environment.NewLine)
My.Computer.FileSystem.WriteAllText("c:\test.txt", Data, False)

Sorry, it's not listview control, but it might give you idea to
manipulate the same thing for listview control.
 
J

John

Read / Write or Save / Load, it's all the same to me!

:)

Thanks,

Seth Rowe [MVP]


but just writing , such as



dim





FileSystem.FileOpen(1, "j:\test\lvobj", OpenMode.Output,
OpenAccess.Write, OpenShare.Shared)



Write(1, listview1.ToString)


does not work , do u know what i'm getting out


lets say u for x = 0 to 19 through and put 20 items out and each item
is a valuue of x and lets say you put 20 different colors out based
on x as well....


I can for eaxh item in listview1.items and put this out for each item
and color


what i'm asking is there an easy way of just writing the object or the
control in one output without iterarting through


Thanks
 
R

rowe_newsgroups

but just writing , such as

dim

        FileSystem.FileOpen(1, "j:\test\lvobj", OpenMode.Output,
OpenAccess.Write, OpenShare.Shared)

 Write(1, listview1.ToString)

does not work , do u know what i'm getting out

lets say u for x = 0 to 19 through and put 20 items out and each item
is a valuue of  x and lets say you put 20 different colors out based
on x as well....

I can for eaxh item in listview1.items and put this out for each item
and color

what i'm asking is there an easy way of just writing the object or the
control in one output without iterarting through

Thanks- Hide quoted text -

- Show quoted text -

The closest thing I could think of was serialization, which is
dramatically different than just calling .ToString() with a
filestream. I did a quick test just now and it seems that the listview
cannot be directly serialized, so your best bet is to either inherits
from the listview and implement your own serialization handler (a
large, painstaking task) or to serialize the datasource of the
listview as mentioned above.

Thanks,

Seth Rowe [MVP]
 
Top