Jump to content

Problema ao gravar determinado conteudo de uma ListView


estica

Recommended Posts

Amigos eu tenho uma ListView com um determinado conteúdo e grava tudo na boa... Mas se eu organizar por exemplo por ordem alfabética os itens já dá erro ao gravar...

Dim File As System.IO.StreamWriter

Dim P As Integer

Dim S As String
File = My.Computer.FileSystem.OpenTextFileWriter(Application.StartupPath & "\" & FileName, AppendTo)

For P = 0 To Listview.Items.Count - 1
S = Listview.Items.Item(P).Text & "," & _
Listview.Items(P).SubItems(1).Text & "," & _
Listview.Items(P).SubItems(2).Text & "," & _
Listview.Items(P).SubItems(3).Text & "," & _
Listview.Items(P).SubItems(4).Text & "," & _
Listview.Items(P).SubItems(5).Text
File.WriteLine(S)

Next
File.Close()

Este é o método que uso para gravar... Agora a minha pergunta é... não seria melhor fazer reset do arquivo antes de gravar? E que dá me erro.

Link to comment
Share on other sites

For each item as ListviewItem in listview.items
Dim values = string.empty
for each subitem as listviewsubitem in item.subitems
values += subitem.Text & ","
next
values += Environment.Newline 'para fazer a mudança de linha.
File.AppendAllText(Application.StartupPath & "\" & FileName,values)
Next

Quando postares alguma pergunta em que te dê um erro no futuro, posta a mensagem do erro.

  • Vote 1
Link to comment
Share on other sites

For each item as ListviewItem in listview.items
Dim values = string.empty
for each subitem as listviewsubitem in item.subitems
values += subitem.Text & ","
next
values += Environment.Newline 'para fazer a mudança de linha.
File.AppendAllText(Application.StartupPath & "\" & FileName,values)
Next

Quando postares alguma pergunta em que te dê um erro no futuro, posta a mensagem do erro.

Ok amigo. Já resolvi o problema 😉

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.