提交当前脏细胞上点击保存按钮从表格任何的DataGridView [英] Commit current dirty cell on clicking save button from any datagridview on form

查看:154
本文介绍了提交当前脏细胞上点击保存按钮从表格任何的DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个datagridviews一种形式。在保存整个数据集将被序列化到绑定到一个SQL VARBINARY(最大值)的强类型属性工作正常。

I have a form with multiple datagridviews. On save the entire dataset will be serialized to a strongly typed property bound to a sql varbinary(max) Works fine.

当然,目前脏单元将不被这里提到的保存:

Of course the current "dirty" cell will not be saved as mentioned here :

<一个href="http://stackoverflow.com/questions/963601/datagridview-value-does-not-gets-saved-if-selection-is-not-lost-from-a-cell">http://stackoverflow.com/questions/963601/datagridview-value-does-not-gets-saved-if-selection-is-not-lost-from-a-cell

我的问题是,用户可以从一个20中的任datagridviews来临,当他们点击保存。

My problem is the user could be coming from any one of 20 datagridviews when they click SAVE.

有什么办法,总之检查一个肮脏的单元格中的每个DataGridView中犯任何脏细胞保存前(点击另一个文本框控件中保存的伎俩之前,但调用焦点()之前保存文本框的没有)

Is there any way, short of checking for a dirty cell in each datagridview to commit any dirty cell before the save ( clicking another textbox control before the save does the trick but calling the focus() of that textbox prior to the save does not )

我在想也许赶上离开网格的事件,但它似乎是基地的问题是点击一个按钮(原因我想我明白)不火引发LostFocus事件的当前控件,它似乎没有点击处理程序ARGS知道最后的当前选定的控件是什么。

I was thinking perhaps catching the event of leaving the grid but it seems the base problem is clicking a button (for reasons I think I understand) does not fire lostfocus events for the current control and it doesn't seem the click handler args knows what the last current selected control is.

指导AP preciated。

Guidance appreciated.

TIA

推荐答案

胡克所有datagridviews同一个离开事件处理程序。休假事件click事件之前处理。在你的假期活动,捕捉刚刚失去焦点的datagridview的。当点击保存按钮,检查所剩下的最后一个数据网格视图有未保存的数据...

Hook up all your datagridviews to the same Leave event handler. The leave event is processed before the click event. Inside your leave event, capture the datagridview that just lost focus. When the save button is clicked, check if the last datagrid view that was left has any unsaved data...

例如:

    DataGridView _lastDataGridView = null;
    private void dataGridView_Leave(object sender, EventArgs e)
    {
        _lastDataGridView = sender as DataGridView;
    }

    private void saveButton_Click(object sender, EventArgs e)
    {
        if (_lastDataGridView != null)
        {
            // check if data needs saving...
        }
    }

修改1: 至于click事件之前,你没有收到请假事件,我没有看到这种行为。要重现我做了什么,创建一个DataGridView和一个按钮的形式。添加两个文本框列到DataGridView,如挂钩的事件,看看是否执行sendButton_Click当_lastDataGridView成员设置。这是我的结束。

Edit 1: As for you not receiving the leave event before the click event, I'm not seeing that behavior. To reproduce what I've done, create a form with a DataGridView and a button. Add two text box columns to the DataGridView, hook up the events as described and see if the _lastDataGridView member is set when executing sendButton_Click. It is on my end.

编辑2: 经过努力我的DataGridView我注意到,数据总是被保存。因此,我怀疑你有一些不同的设置。我打开VirtualMode。这将导致你所描述的相同的行为。如果可能的话,请尝试关闭VirtualMode关上,如果数据被保存到DataGridView预期。否则,尝试实施这个MSDN文章中概述的建议。

Edit 2: After trying my datagridview I noticed that the data was always being saved. So I suspected you had some different settings. I turned on "VirtualMode." This causes the same behavior that you're describing. If possible, try turning VirtualMode off and see if the data gets saved to the DataGridView as expected. Otherwise try implementing the suggestions outlined in this MSDN article.

这篇关于提交当前脏细胞上点击保存按钮从表格任何的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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