I've got a DevExpress TcxGrid, with an event handler attached to its GridView's OnEditValueChanged event that's supposed to summarize some data in one of the columns. Problem is, this event gets fired during validation, before the updated value has been written to the underlying dataset. I'm not too familiar with the TcxGrid. Does anyone know if there's a way to fire an event handler after the dataset has been updated?
我有一个DevExpress TcxGrid,它的GridView的OnEditValueChanged事件附加了一个事件处理程序,它应该汇总其中一个列中的一些数据。问题是,在将更新的值写入基础数据集之前,此事件在验证期间被触发。我对TcxGrid不太熟悉。有没有人知道在数据集更新后是否有办法触发事件处理程序?
4 个解决方案
#1
What about using the DataSource.OnDataChange event?
那么使用DataSource.OnDataChange事件呢?
#2
I'm not sure if this is exactly what you need, but I have found the ImmediatePost option of the grid to be very useful for situations where I need to update a summary - it's buried under its Data Controller property of the cxView. This makes the grid act like a spreadsheet - as soon as the user presses enter or tab in a cell, the record gets posted. Then I would have my summarising event fire from the AfterPost event of the dataset, perhaps?
我不确定这是否正是你所需要的,但是我发现网格的ImmediatePost选项对于我需要更新摘要的情况非常有用 - 它隐藏在cxView的Data Controller属性下。这使得网格就像电子表格一样 - 只要用户按下单元格中的输入或制表符,记录就会被发布。那么我可能会从数据集的AfterPost事件中获取总结事件吗?
(You probably already know this but the gridview itself has a lot of very useful summarising options built into it - look at the Summary properties of the columns, and make sure ShowFooter is set to true in the ViewOptions - so if your summary is a relatively simple total or average or similar, let the grid do it all and save yourself some work.)
(您可能已经知道了这一点,但gridview本身内置了许多非常有用的摘要选项 - 查看列的Summary属性,并确保ViewOptions中的ShowFooter设置为true - 所以如果您的摘要是相对的简单的总或平均或类似,让网格做到这一切,并为自己节省一些工作。)
#3
Do you use the cxTableView or cxDBTableView in the cxGrid
您是否在cxGrid中使用cxTableView或cxDBTableView
if you use the cxDBTableView then you set your event in the datasource.onchange of the linked datasource in the property of the cxDBTableView. (cxDBTableView .datacontroller.datasource)
如果使用cxDBTableView,则在cxDBTableView属性中的链接数据源的datasource.onchange中设置事件。 (cxDBTableView .datacontroller.datasource)
#4
I'd go with skamradt : look more carefully for an event which matches your expectations.
我会选择skamradt:仔细观察符合您期望的活动。
Otherwise, you can plug your event after making sure your data is initialized :
否则,您可以在确保数据初始化后插入事件:
procedure TMyGrid.MyProc_OnDataLoaded( Sender : TObject ); //I made up this event, I'm not sure it exists
begin
Self.OnEditValueChanged := MyProc_OnEditValueChanged;
end;
I would strongly advise you to NOT use this as a regular developping habbit (making an event set another callback through code is a sure way to debugging hell), but if you really don't find any other way to do it...
我强烈建议你不要将它用作常规的开发习惯(通过代码设置一个事件设置另一个回调是调试地狱的可靠方法),但是如果你真的没有找到任何其他方法来做到这一点......
#1
What about using the DataSource.OnDataChange event?
那么使用DataSource.OnDataChange事件呢?
#2
I'm not sure if this is exactly what you need, but I have found the ImmediatePost option of the grid to be very useful for situations where I need to update a summary - it's buried under its Data Controller property of the cxView. This makes the grid act like a spreadsheet - as soon as the user presses enter or tab in a cell, the record gets posted. Then I would have my summarising event fire from the AfterPost event of the dataset, perhaps?
我不确定这是否正是你所需要的,但是我发现网格的ImmediatePost选项对于我需要更新摘要的情况非常有用 - 它隐藏在cxView的Data Controller属性下。这使得网格就像电子表格一样 - 只要用户按下单元格中的输入或制表符,记录就会被发布。那么我可能会从数据集的AfterPost事件中获取总结事件吗?
(You probably already know this but the gridview itself has a lot of very useful summarising options built into it - look at the Summary properties of the columns, and make sure ShowFooter is set to true in the ViewOptions - so if your summary is a relatively simple total or average or similar, let the grid do it all and save yourself some work.)
(您可能已经知道了这一点,但gridview本身内置了许多非常有用的摘要选项 - 查看列的Summary属性,并确保ViewOptions中的ShowFooter设置为true - 所以如果您的摘要是相对的简单的总或平均或类似,让网格做到这一切,并为自己节省一些工作。)
#3
Do you use the cxTableView or cxDBTableView in the cxGrid
您是否在cxGrid中使用cxTableView或cxDBTableView
if you use the cxDBTableView then you set your event in the datasource.onchange of the linked datasource in the property of the cxDBTableView. (cxDBTableView .datacontroller.datasource)
如果使用cxDBTableView,则在cxDBTableView属性中的链接数据源的datasource.onchange中设置事件。 (cxDBTableView .datacontroller.datasource)
#4
I'd go with skamradt : look more carefully for an event which matches your expectations.
我会选择skamradt:仔细观察符合您期望的活动。
Otherwise, you can plug your event after making sure your data is initialized :
否则,您可以在确保数据初始化后插入事件:
procedure TMyGrid.MyProc_OnDataLoaded( Sender : TObject ); //I made up this event, I'm not sure it exists
begin
Self.OnEditValueChanged := MyProc_OnEditValueChanged;
end;
I would strongly advise you to NOT use this as a regular developping habbit (making an event set another callback through code is a sure way to debugging hell), but if you really don't find any other way to do it...
我强烈建议你不要将它用作常规的开发习惯(通过代码设置一个事件设置另一个回调是调试地狱的可靠方法),但是如果你真的没有找到任何其他方法来做到这一点......