views:

953

answers:

2

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).

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

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

+2  A: 

Check out the cell formatting event.

There is an example there that should work for your scenario.

Dan
+2  A: 

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.

GWLlosa