problems editing dataGrid and 'Tab' delimited text file
StreamReader reader = File.OpenText("mystations.txt");
string line = reader.ReadLine();
while (line != null)
{
// string[] stationtxt = line.Split('\t');
string name = line.Split('\t')[0];
string url = line.Split('\t')[1];
string desc = line.Split('\t')[2];
Image img = Image.FromFile("c:/pictures/"+ name + ".jpg");
line = reader.ReadLine();
dgLogo.Image = new Bitmap(img);
dataGridView1.Rows.Add(name, url, desc, img); //(stationtxt);
}
reader.Close();
reader.Dispose();
I'am able to edit the values in the datagrid but when i reload the form it display the original values of course.
i want to catch the edited values and save it again to the tab delimited text file.
and also be able to delete a row from the text file and datagrid.
the image column is there just for display its not editable.
if someone can provide me a sample or point me in the right direction
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
If you split your data into a list of array of string, you can do a bit of googling and find how to use a list as a data source, then when they finish, just tab join the data back and write it out.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
believe me a read a lot of guides and the worst are from msft msdn website there samples never works.
i have the logic in my head. the problem is converting that to code, in where event to add it. datagrid have a lot lot of events,
for example i have to added to oncellchange event, onclick event, on edit event.
all codes have very different methods and it get confusing.
-thanks BTW, I think you reply to my other post, right?
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
I had this working fairly quickly when I tried it, I dont have the machine to hand I did it on, but I took a csv file and chucked it into a list of array of string and then added it.
As for your other post - which one?
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
As for your other post - which one?
the one i have problem lunch a batch file from the code.I took a csv file and chucked it into a list of array of string and then added it.
ok the problem is how to get the new edit values from the datagrid i cant use the Arraylist because of the image column in the datagrid with the array i dont find how the get the images show up i end up doing in it like the code i show in the other post.
so my doubt is not how to add the text file to the datagrid I did that already. is how to get the new edited values once the user edit them directly in the datagrid. then get all the values from the datagrid and save them back to the 'tab' delimited text file.
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
You dont, or rather you shouldn't need to it should all be done for you..
remember am not using any database or dataset. I know this is automatically if you are connect to a database.
i am reading from a text file and passing that values to the datagrid for easy viewing and (possible and hope so) easy editing.
or do you mean this could be done even if i am not using a database?
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
You didnt read the link I posted then, as thats exactly what that does. You can use lists as data sources.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
I know I read it but if you see my code I fill the datagrid individually because of the image column if I use the list how I fill the images column because my textfile only contain the name of the image file, the image is in another folder and the datagrid column is a DataGridViewImageColumn.
i was trying the code from the page you post when i encounter the problem of the image.
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
You should be able to make an image part of the row.. without any major issues.. Then it would update properly
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
(men/girl) am so confuse right now !!
i really dont know or get how to implement that to my code !
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
Normally you would create a class which included the picture, and then have a list of the class, but a picture wouldnt ever save in a csv file without potential issue so, if its just a icon to cover a given predetermind set of options (such as read, write, execute or such) then you could use enums and so on.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
ok you say that i have to :
1. parse the text file to an Array or ArrayList ?
2. convert that Array or ArrayList to a dataSource
3. use that dataSource to populate the datagrid
4. use the INotifyPropertyChanged Interface of the page you post, to update accordingly the dataSource , Array or ArrayList and the text file.
questions? how I fill the image column alone, or i have to put the images as part of the array or arrayList, also known that the images files depend on the name of a value in the text file that is the name of the file plus the .jpg extension as you saw in my code.
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
1. Array
2. You dont "convert"
3. yes
4. it updates the list, not the file, you still need to write that at the end
Thats why the image is in the class you were supposed to be making from the last post I did.. It will then populate the grid.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
thanks a lot really. but be easy on me
i am trying to learn C# and am surprise i was able to make an application already this are just things am still adding to it but the application is running and working. I like to learn by doing projects and working with the program itself I am waiting for a book to read a little but mostly for reference, there are 2 many to choose for. I will have to go to Borders and check them out first.
A few month back I take a class on C++ and like it so i pick a newer and modern language no so distant.
here is the application i did and still working on it, the bottom part is the one I am trying to make it work.
http://thegreenbutton.com/forums/ShowThread.aspx?PostID=287192#287192
1. Array
2. You dont "convert"
3. yes
4. it updates the list, not the file, you still need to write that at the end
1.you make an array
2.you bind the array to a datasource
3 and bind that datasource to the datagrid
4 it update the array ?
the class part i get lost I know what a class is but what am suppose to declared or define there about the images ?
- from where you load it and/or to where you save them ?
- and stuff like that
thanks again!
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
Did you try following the MS example I linked? Which had a working list of a "class" that updated? (worry about the image part separately but basiclaly its just another part of the class)
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
ok I really try to fallow that example with no avail . I dont understand a few lines or what they does because the complete code dont apply to me and the most simple dont work that is fill the datagrid.
I create an ArrayList and declare a binding source then declare that binding source as my datasource for my array
then bound the datagrid with the bounding source.
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
OK, but perhaps your current way is why its not working - the example is very similar to what you wanted, in fact its where I grew mine from, so it does work. If you dont understand it, post the exact bits you dont understand and what you thought it should do as otherwise its going to be impossible to move you on from this.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
really I can get this to work am trying first to make a datatable and binding with the datagrid . but I get confuse on what are the steps so someone please correct me
1. you create a data table
2. you create a binding source based on the data table
3. you bind the datagridview with the binding source
??
this is the mess of the code i was trying to make the table and the binding, ect...
BindingSource bindingSource = new BindingSource();
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Data");
bindingSource.DataSource = ds;
dataGridView1.DataSource = bindingSource;
StreamReader reader = File.OpenText("mystations.txt");
string line = reader.ReadLine();
DataRow dr;
Regex r = new Regex("\t");
line = reader.ReadLine();
while (line != null)
{
foreach(Match m in r.Matches(line))
{
dr = dt.NewRow();
dt.Rows.Add("Name", typeof(string));
dt.Rows.Add("URL", typeof(string));
dt.Rows.Add("Desc", typeof(string));
dt.Rows.Add("Logo", typeof(string));
dt.Rows.Add(dr);
}
}
reader.Close();
reader.Dispose();
}
could someone help fix this and/or explain me the process..
thanks!
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
reaven
Junior Poster in Training
52 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0