Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

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
Posted
Comments
[no name] 28-Sep-13 9:51am    
So split the string on the ";" and add the items to your listview
Add a Delete button and when it's click, delete the selected item in you listview.
What exactly is the problem?
Clevie7 28-Sep-13 10:03am    
the problem is, i wanna load the .txt splitted into a listview IDK how to do that, and idk how to delete it, i mean the code, can u please tell me the code
[no name] 28-Sep-13 10:18am    
Sure I can write the code for you. I charge $250 USD per hour with a 4 hour minimum. I am booked solid until December so you will have to wait until then. If you can't wait then maybe you could read the documentation for the controls and try and write some code yourself.
Clevie7 28-Sep-13 12:00pm    
Dafuq?, I will pay $1000 for a f***ing simple thing lol, are u **** .. no sorry, i know all these things easier from utube than paying $1000 jesus!
[no name] 29-Sep-13 9:22am    
Then feel free to actually do it yourself then. If it's so easy then why are you begging for someone to write the code for you?

1 solution

A ListView is probably not what you want to use - it really isn't setup for that kind of thing, unless you display each line as a separate string - I don't think from your description that that is what you are trying to achieve. But...
C#
string rawData = @"setting1:true;setting2:false;setting3:true;";

Or:
C#
string rawData = File.ReadAllText(@"D:\Temp\Settings.txt");

Then:
C#
string[] pairs = rawData.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string pair in pairs)
    {
    listView1.Items.Add(pair);
    }
Will do it - sort of.

But you might be better off using a "more structured" control, such as a DataGridView:
C#
string rawData = @"setting1:true;setting2:false;setting3:true;";
string[] pairs = rawData.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
foreach (string pair in pairs)
    {
    string[] kv = pair.Split(':');
    list.Add(new KeyValuePair<string, string>(kv[0], kv[1]));
    }
dataGridView1.DataSource = list;
 
Share this answer
 
v2
Comments
pdoxtader 28-Sep-13 10:38am    
I think he was hoping for a vb.net solution Griff...

- Pete

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900