如果我关闭窗体而不保存,则在Datagrid单元格中显示文本 [英] Show Text In Datagrid Cell If I Close Form Without Saving

查看:68
本文介绍了如果我关闭窗体而不保存,则在Datagrid单元格中显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CodeProject会员。

我有一个数据网格表单。我想如果我在datagrid单元格中键入一些文本并关闭表单而不保存,我再次加载表单然后旧文本应该显示在datagrid单元格中。



在此先感谢.. 。

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...

推荐答案



诀窍是捕获ApplicationExit事件。这是通过编写一个在窗体关闭时调用的事件处理程序来完成的。我个人使用应用程序出口作为我的触发器。您还可以使用FormClosing事件。例如:


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:

// ****************************************** 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:

Application.ApplicationExit +=
                new EventHandler (
                        Application_Exit );



您的表单构造函数中还包含用于确定是否存在任何早期保存数据的代码。仅仅存在一个文件就足够了。如果是这样,请检索它并填充DataGrid。


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.



确保将用户数据保存在用户可访问的用户唯一文件中。我建议不要使用cookies,因为它们可能会在机器上被禁止。


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.


这篇关于如果我关闭窗体而不保存,则在Datagrid单元格中显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆