AutoGenerateColumns and setting properties on them (aka using CreateColumnSet)...

http://weblogs.asp.net/sibrahim/archive/2004/02/13/72711.aspx

Samer seems to be getting pretty upset with the AutoGenerateColumns implementation in ASP .NET's DataGrid.  I think I can help out a bit though.  It turns out that the CreateControlHierarchy method is where quite a bit of DataGrid magic tends to happen.  A call is made into CreateColumnSet which is a protected override method, meaning derived controls can make use of it.  What exactly does this method return?  Well, it creates a composite of all autogenerated columns along with any bound columns and returns those back to CreateControlHierarchy.

Now of course, the method it calls to generate your automatic columns is hidden (private), so you can't call it directly, but if you override CreateColumnSet you can get back ALL columns including autogenerated columns as an ArrayList.  This gives you the opportunity to add even more columns if you wanted to (maybe conditional expression columns depending on the autogenerated columns), set any state on the columns, or mess with any properties (in Samer's case, the formatting properties).

Published Friday, February 13, 2004 4:18 PM by Justin Rogers
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)