的ItemDataBound为Windows窗体DataGridView? [英] ItemDataBound for a Windows Forms DataGridView?

查看:114
本文介绍了的ItemDataBound为Windows窗体DataGridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绑定一个数组来一个DataGridView。我有它映射到按键一列包含列的文件路径。我想pre-过程中的文件路径,以便DataGridViewButtonColumn仅显示文件名(没有父文件夹)。

I am binding an array to a DataGridView. I have a column containing file paths which maps to a column of push buttons. I would like to pre-process the file path so that the DataGridViewButtonColumn displays only the file name (sans the parent folders).

我如何拦截和pre-过程值就必然要一个DataGridView的列之前?

How do I intercept and pre-process values before they are bound to the columns of a DataGridView?

(我见过这样的事情在ASP.NET中的数据绑定,并希望我能在这里做同样的。)

(I have seen something like this in ASP.NET data binding and was hoping I could do the same here.)

推荐答案

处理的CellFormatting事件。你会得到的重新presents未格式化的值的事件参数传递的值。把它和分析它(Path.GetFileName())或类似的东西),并设置ConvertEventArgs.Value属性设置为您新的字符串。将FormattingApplied标志为真,以prevent进一步的格式化事件。那现在应该包括你。

Handle the CellFormatting event. You're going to get a value passed in from the event args that represents the unformatted value. Take it and parse it (Path.GetFileName()) or something like that), and set the ConvertEventArgs.Value property to your new string. Set the "FormattingApplied" flag to true, to prevent further formatting events. That oughta cover you.

这篇关于的ItemDataBound为Windows窗体DataGridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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