Click here to Skip to main content
16,003,345 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi CodeProject Member.
i have a datagrid form . i want if i type some text in datagrid cell and close form without saving and again i reload form then old text should show in datagrid cell .

Thanks in Advance...
Posted
Comments
[no name] 30-Mar-14 8:52am    
Well you have to save the data somewhere. Programming != magic.
guru14 30-Mar-14 8:59am    
i know programming != magic .
if you know then tell me how to save somewhere.
[no name] 30-Mar-14 9:07am    
If you know that then why did you ask for magic? I can't read your mind to know what it is that you have tried, what research you have done, what code you have written or what problem you have. Do you really expect me to waste my time trying to figure out where you want your data saved? What have you done?
gggustafson 30-Mar-14 11:45am    
You are being testy. I don't need to waste my time reading your response if you continue responding poorly to an obviously new OP.
[no name] 30-Mar-14 13:57pm    
Nobody asked you to waste any time at all. If you don't feel the need to read then don't. I don't feel like wasting my time reading your solution which is not what the OP asked for. So I guess we are even.

1 solution


The trick is to catch the ApplicationExit event. This is done by writing an event handler that will be invoked when the form is closed. I personally use the application exit as my trigger. You could also use the FormClosing event. An example:


C#
// ****************************************** Application_Exit

void Application_Exit ( object    sender,
                        EventArgs e )
    {

    // Place your data saving code here

    }


Then declare the event handler in your form constructor, like:


C#
Application.ApplicationExit +=
                new EventHandler (
                        Application_Exit );


Also in your form constructor include code to determine if there is any earlier saved data. The mere existence of a file should be sufficient. If so, retrieve it and populate your DataGrid.



Make sure that you save the user's data in a user-accessible user-unique file. I recommend against using cookies as they may be prohibited on the machine.



Hope that helps.

 
Share this answer
 
v2

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