everything working great !!!!
edit, add, delete. perfect

just one little problem, is the only one...!

how i can rename the images from where the name have been edited.

-the datagrid have 4 column name - url - desc - images-
-the image is named after you enter something in the <name> column
- if you edit the name of an already entered record the programs doesnt found the image
because is still name with the old <name> value

thats the only thing!!

thanks everyone for everything...


I was thinking in get all the files in the
directory using the GetFiles method.

but i will need the two values, the old one to compare to get the original file and the new one to rename it.

---think, think, think !!!
how i keep the old value.


got it !!

if there a more direct way.

creat two strings oldValue and newValue

set to catch the old one on cellbeginedit and the new on cellendedit

check and have both values .

now is get the files compare against the old value and rename right ?


ok.. no not got it ...
my images is named the same as the name in the name column if you edit the name value later it wont find the image because the name is not the same i have to change the image name with the name new value everytime someone edit the name column.

I am using this

DirectoryInfo di = new DirectoryInfo("c:/images/");.
        FileInfo[] fi = di.GetFiles();

how I compare the two values so i can rename it with the new one

also in wat event i can do that because i try in the cellvaluechange event but when i press the cell to edit if i finish edit and press enter the cell focus change to the next one and the value too.

also when compile i throw an error because the variable new value is null of course because you haven't edit anything yet.

is there a more reliable way to do this and rename the image with the new value


I already managed to get right both values of the current edit cell and rename the current images according to those values of course now i want to delete the image with the old value because i am using File.Copy the same as File.MoveTo but with copy it let me run the program because both files can exist the other deleted the old file by default.

the problem i can delete it because is in use here

StreamReader reader = File.OpenText("mystations.txt");
            string line = reader.ReadLine();
            while (line != null) //((line = reader.ReadLine()) != null)

                string name = line.Split('\t')[0];
                string url = line.Split('\t')[1];
                string desc = line.Split('\t')[2];
                Image img = Image.FromFile("c:/Users/" + MyGlobals.user + "/test/" + name + ".jpg");

                dataGridView1.Rows.Add(name, url, desc, img); 
                line = reader.ReadLine();


and i cant Dispose img , the one giving me the problem because the datagrid depend on him even so when the file is already rename the datagrid is using the old one until I close the application and open again.

is there a way i can make the img dispose and take the new values.

even dispose the datagrid at the application close event dont work.

Please HELP !!!!!!!


how I can reuse it if the images are not the same ?

there isn't another way like make a background class that trigger when the application close and delete it ?


could you be more specific. I dont fallow .
because after a lot of edit at the name column there would be a lot of images in the image folder.... how i can avoid that.

anyway i put the application to save in a txt file all the images to delete after and edit session.
and make a backgrond app. that watch for the process name of the main application if the application is not running it then goes and delete all the images files in the txt file.


I am calling this application from the main one at closing. and its not working.
how i call application 2 from apps. 1, close apps. 1 and leave running apps. 2


In your code you show the img object created, and loading a picture, once loaded obviously it remains in memory and technically wont need to be on the disk.. however, to replace the image, you dont need a new img object, just to change the picture in it.

As for the deleting of files, rather than have some background app that gets overly complex, create an object which holds a stringlist, which inherits from the disposable range, and then in the dispose have it remove the items in your list.


I get the idea but you lost me again in how to implement that.



which inherits from the disposable range, and then in the dispose have it remove the items in your list.

dont get that. also,
I create the stringList

StringCollection stringList = newStringCollection();
stringList.add= ????

where i put that ? inside stReader()
and what I add to the list the images.


Have a read on IDisposable - that will cover the disposal comment

The stringlist would be part of your new class you made from IDisposable, so that when it goes you can itterate through the things you need to do..

You then add to the list each time you change the image reference, to place the old unwanted item on the list for removal when its all over.

Votes + Comments
thanks for the help

Have a read on IDisposable - that will cover the disposal comment

I end doing this inside my while loop

var imgClone = img.Clone() as Image;

outside of the loop I delete the file.
I was missing Clone();

it works pretty well now. thanks a lot..!

* if there's anything else I should know send me a private msg.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.