DataGridView 绑定
我有一个通过通用列表绑定到的网格视图。 我自己设置了所有列。 我只是想:
在编辑行时捕获事件 PRE 格式错误 - 通过隐藏字段获取行信息 - 并坚持
我确信这一定很容易,但我没有对表单工作做太多工作,我不熟悉其 DataGridViews 事件。
I have a gridview that I am binding to via a generic list. I have set all the columns myself. I am just trying to:
Catch the event PRE format error when a row is edited- get the row information via a hidden field - and persist
I am sure this must be pretty easy but I haven't done much with forms work and I am unfamiliar with its DataGridViews Events.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种看待这个问题的方法:
TypeConverter
我通常更喜欢后者,因为它使此逻辑远离 UI; 我会看看是否可以做一个例子...
示例(大部分代码是“显示它工作”代码); 在这里,我定义了一个
MyDateTimeConverter
,它将日期格式化/解析为其向后“dd MMM yyyy”文本(没有真正好的理由),并将该转换器与其中之一相关联特性。 您可以编辑网格中的值,更改将被推回(更改行以查看“实际”值更新)。 由于更改通知存在一些细微差别,它不会立即显示; 仅仅为此而使示例变得更加复杂是不值得的......There are two ways of looking at this;
TypeConverter
on the propertyI usually prefer the latter, since it takes this logic away from the UI; I'll see if I can do an example...
Example (most of this code is the "show it working" code); here I define a
MyDateTimeConverter
, which formats/parses dates as their backwards "dd MMM yyyy" text (for no really good reason), and associate that converter with one of the properties. You can edit the values in the grid, and changes are pushed back in (change rows to see the "actual" value update). It doesn't show immediately because of some nuances around change-notification; it wasn't worth making the example more complex just for this...