Jump to content

Saving values from a listview

- - - - -

  • Please log in to reply
8 replies to this topic

#1
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
Hi

I've got a form in Visual Basic 2010 that has a Listview. Users insert something something into a textbox, click a button and then it goes into the listview. I need a way of saving this. I really don't care what format, it could be notepad or Excel for what I care.

Does anyone know how to do this? Any help would be appreciated.

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
If you don't care what format its in, loop through the contents of the listView and write them to a .txt file, then save when done.

If you have problems post back.
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
You mean type them in manually? I need the program to save it, as more will be added alot of the time, and I won't be the one who is using the program. Doesn't the Listview have an option of saving to any type of format?

#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
No I don't mean manually.

I mean something like this:
for(int i = 0; i < listView1.Length-1; i++)
{
write.toFile(listView1.Index(i))
}

The above code is more C# than VB, and doesn't work, but that should give you an idea. If you don't know how to wright to a file try this: Visual Basic .NET programming for Beginners - How to Write to a Text File
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#5
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
create/open a file
use a for each, then save the items to the file.
close the file.

#6
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
Cheers, I'll check it out later on and see how it works.

#7
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
For i As Integer = 0 To ListView1.Items.Count - 1
sw.Write(ListView1.Items(i).Text)
For subItemIndex As Integer = 1 To ListView1.Items(i).SubItems.Count - 1
sw.Write("testviewbox" & ListView1.Items(i).SubItems(subItemIndex).Text)
Next
sw.Write(Environment.NewLine)[/B]

Every time I try and save it anywhere on my hard drive, I get this error:
"Access to the path 'C:\Users\Francis\Documents' is denied.

Not only do I get this for this folder, though I also get it for C:\ and a folders.

I have also tried changing the settings in app.manifest to <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Is there any solution to this problem? Any help would once again be appreciated.

#8
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
I believe you may be running Windows7 or Vista. If so, run the program as Administrator.

Another thing, although it has nothing to do with your problem, you should use a foreach instead of a for loop whenever possible.

#9
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
Resolved, I was only putting where to put the file, and not the file name.

Thanks for your help.

Francis.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users