DataGridView的事件数据源更改之前, [英] DataGridView Event Before DataSource Changes
问题描述
有好歹我可能引发的 DataSourceChanging 事件的DataGridView。在DataGridView有 DataSourceChanged 之后数据源绑定到DataGridView事件,(我相信)。我想要做一些东西的属性被更改了。
Is there someway I could trigger DataSourceChanging event in DataGridView. The DataGridView has DataSourceChanged event which (I believe) after DataSource is bound to the DataGridView. I want to do some stuff before the property gets changed.
我的一个样本code ...
A Sample code of mine...
private void LoadGrid()
{
// I do some things like saving user settings here
DtgRefundAssign.DataSource = BLL.GetDataSource(parameter1, parameter2); //Just to illustrate
// And restore them after the datasource is bound
}
我需要做类似的东西很多形式。只是想开发一种确实这是一个普通的程序,每当数据源发生变化。可以用DataSourceChanged事件进行恢复部分...但是这事件应该怎么处理这样做节省了一部分?
I need to do similar stuffs in many forms. Just thinking to develop a common procedure which does this, whenever the datasource is changed. The restoring part can be done using DataSourceChanged event... But which event should I handle to do the saving part ?
推荐答案
我没有这样做我自己,但DataGridView的不密封,所以你应该能够创建一个新的类继承自它。创建一个新的事件DataSourceChanging,然后覆盖DataSource属性的二传手,使得它首先引发该事件,然后的实际上是设置在父类中的属性。
I haven't done this myself, but DataGridView isn't sealed so you should be able to create a new class that inherits from it. Create a new event "DataSourceChanging", then override the DataSource property's Setter so that it first raises that event, then actually sets the property on the parent class.
您会那么简单地使用DataGridView的代替默认之一,并把您的拯救逻辑DataSourceChanging。
You'd then simply use that datagridview in place of the default one, and hook up your save logic to DataSourceChanging.
这篇关于DataGridView的事件数据源更改之前,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!