Synfusion WinForms 网格控件:当单元格内容更改时我可以订阅哪些事件
我已经使用这个“API”很多年了(是的,用引号引起来,因为它可能是我遇到过的最令人困惑的 API!)
我的需求非常简单。 我想订阅一个事件,该事件告诉我单元格的内容已更改以及新内容是什么。
有一千零一个事件被触发,告诉您何时单元格已更改,但当您查询单元格关联 GridStyleInfo
的 .Text
属性时,它总是告诉您它WAS是什么,而不是它是什么。
这对于 CurrentCellChanging
或 CurrentCellValidating
等事件来说足够公平。我读到您可以在这些事件期间向当前单元格的“渲染器”询问其值。
对我来说,似乎不对的是当我订阅 CurrentCellValidated
时 - 单元格文本仍然是旧值。因此,CurrentCellValidated
(我假设)意味着单元格的内容已更改,验证已开始,验证已结束,验证已成功,但是...发生了什么已验证,它在哪里?
我知道我在 StackOverflow 上的下一个问题是什么 - 我会给你一个提示:它包含“SyncFusion”、“Grid”、“Alternative”等词!
干杯,
史蒂夫
It's been many years since I've used this "API" (yes, in quotes, as it's possibly the most confusing API I've ever come across!)
My need is a very simple one. I want to subscribe to an event that tells me that a cell's content has changed and what the new content is.
There are a thousand and one events fired that tell you when a cell has changed, but when you query the .Text
property of the associated GridStyleInfo
for the cell, it always tells you what it WAS and not what it IS.
This is fair enough for events like CurrentCellChanging
or CurrentCellValidating
. I've read that you can ask the 'Renderer
' of the current cell for it's value during these events.
What doesn't seem right to me is when I subscribe to CurrentCellValidated
- the cells text is still the old value. So, CurrentCellValidated
(I assume) means that the cell's content has changed, validation has started, validation has ended, validation has succeeded, but... what's been validated and where is it?
I know what my next question on StackOverflow is going to be - I'll give you a hint: it contains the words 'SyncFusion', 'Grid', 'Alternative'!!
Cheers,
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在将更改的值移动到基础样式对象之前,会引发 CurrentCellValidated 事件。如果您想在更改的值移至基础样式对象后捕获更改,请尝试使用 CurrentCellAcceptedChanged 事件。
下面的示例展示了如何使用这两个事件。
The CurrentCellValidated event is raised before the changed value is moved into the underlying style object. If you want to catch the change after the changed value has been moved into the underlying style object, then try using the CurrentCellAcceptedChanged event.
Here is an example that shows how to use both events.
正如 Clay 所说,CurrentCellAcceptedChanges 事件将是在将值存储到 GridStyleInfo 后获取该值的正确位置。
添加更多信息 - 网格在执行任何验证之前引发 CurrentCellValidating。如果您查看 GridStyleInfo,会发现有诸如 CellValueType(int、decimal、datetime 等)、Format 和 CultureInfo 之类的属性。当您设置这些属性时,Grid 将根据这些属性解析单元格值。如果是绑定控件 - GridDataBoundGrid 或 GridGroupingControl,它将从数据源的架构(如果可用)中读取它。
因此,CurrentCellValidating 在任何验证之前被触发,CurrentCellValidation 在 Grid 解析之后和保存到 GridStyleInfo.CellValue 之前被触发。
As Clay said, CurrentCellAcceptedChanges event would be the correct place to get the value after it has been stored to the GridStyleInfo.
Adding more info - Grid raises the CurrentCellValidating before it does any validations. If you look at the GridStyleInfo, there are properties like CellValueType (int, decimal, datetime, etc), Format and CultureInfo. When you set these properties, Grid would parse the cellvalues based on these. In case of bound controls - GridDataBoundGrid or GridGroupingControl, it would read it from the datasource's schema (if available).
So CurrentCellValidating is fired before any validations, CurrentCellValidation is fired after Grid does it's parsing and before it saves to the GridStyleInfo.CellValue.