hello im stuck please help

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
8 posts Page 1 of 1
Contributors
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

hello im stuck please help
troop
hello im new here, but i really need answer for this i hope i will stay on this awesome forum for so long

ok, first i use visual studio 2010, im making app that

you have a textbox and a button called Open List, when you click on it, it will Open the .txt file from the textbox location.

you got me? ok

now the .txt file looks like
setting1:true;setting2:false;setting3:true;
so its Setting : [true,false] or might be other options like if font it will be font:tahoma or size .. etc

so and the ; seperates each setting


now the thing is, "how" can i load this file into a listview, with "Setting, Value" thing, and also

i need to be able to select one of them for example and be able to delete the setting, with a button Delete

please tell me how, i please need this :(

ty
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: hello im stuck please help
muttley1968
Well personally I think it would be easier for you to just save and load two different files one called setting and one called values then load these into two listboxes and then you can just use senders to your listview so it looks good but listboxes are easier to work with in my opinion
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

Re: hello im stuck please help
troop
it will be harder, i mean, when they wanna delete a item, how will the OTher listbox know which item? lol its impossible,

and if this is possible can i get a code please
User avatar
Smiley
VIP - Donator
VIP - Donator
Posts: 269
Joined: Sat Dec 19, 2009 3:39 pm

Re: hello im stuck please help
Smiley
If no one has helped you when i get up tomorrow i'll help
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

Re: hello im stuck please help
troop
thanks

im waiting u muttley if u can tell me the code for list box, i thought it will be better, but it ned to know wich setting is for which value

#Smiley thanks !
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: hello im stuck please help
muttley1968
well I wont tell you the code straight away as its on my laptop at home and im not their right now but ill send it later when I am home

Till then look for Sender.tag you can use the double click event to send a code that would select the same item as the listview and then you would just remove it with a simple listview.itemes.remove (listview.selecteditem)
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: hello im stuck please help
comathi
Here's code that will work for you without having to change the way your files are set up. ie, you'll still have a single file with data in the following format:
setting1:value;setting2:value
The code I'll give you will load data into the listview, delete selected listview items and save the resulting data to the file. If you'd like to also edit values, I can help you out with that as well.

To get this working, you'll first have to make sure your ListView "View" setting is set to "Details", and that you've added to Columns to your Listview. All of this can be edited by clicking on the small arrow that appears in the top right corner of the ListView when you click it in the designer view.

For the purposes of this example, you'll need three buttons, which will each do one thing (load, delete and save).

Code for the first button:
Code: Select all
 If ListView1.Items.Count >= 1 Then
            For Each item As ListViewItem In ListView1.Items
                ListView1.Items.Remove(item)
            Next
        End If

        Dim raw_settings As String = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\settings.txt")
        settings = raw_settings.Split(";")

        For i = 0 To settings.Length - 1
            Dim comp() As String = settings(i).Split(":")
            Dim n As New ListViewItem(comp(0))
            n.SubItems.Add(comp(1))
            n.Tag = i.ToString
            ListView1.Items.Add(n)
        Next
Code for the second button
Code: Select all
For Each item As ListViewItem In ListView1.SelectedItems
            ListView1.Items.Remove(item)
        Next
Code for the third button:
Code: Select all
Dim write_settings As String = ""

        For i = 0 To ListView1.Items.Count - 1
            write_settings = write_settings & ListView1.Items(i).Text & ":" & ListView1.Items(i).SubItems(1).Text
            If Not i = ListView1.Items.Count - 1 Then write_settings = write_settings & ";"
        Next

        My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\settings.txt", write_settings, False)
And finally, outside of any sub, just under the Class declaration:
Code: Select all
Dim settings() as String
Don't forget to change the directories and filenames to the ones you're actually using cooll;
User avatar
troop
Dedicated Member
Dedicated Member
Posts: 75
Joined: Sat Sep 28, 2013 11:57 am

Re: hello im stuck please help
troop
thanks alot comathi

im at my mom house but when i will be back later i will try it and i think i will be able to edit it, i thinks its easy but if u wanna tell me the code i will be happier

BTW, the same question on CodeProject i got a comment saying "i can teach u, for $250 a hour" so i think this site is the best out of all :D thanks !!! loove; loove; loove;
8 posts Page 1 of 1
Return to “Coding Help & Support”