Hi,
Is it possible to change the default behaviour of the WinGrid to display the ToString() of a property in a cell.
For instance, instead of invoking the ToString() method on a class I want to implement a method called FormattedText(), and a want to set the cell display to this result at runtime.
Thanks.
I think you can do it with a DataFilter. You can see a sample here:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=5014
I made a sample of converting TimeSpan to a DateTimeEditor. You can see it in my page:
http://community.infragistics.com/members/jct/default.aspx
I want to avoid the use of an editor as I am not going to edit the contents of the cell but just want to change the way the value in the cell is displayed.
I will try it if there is no other way to get the desired results.
Don't be scared off by the word "editor" Using an editor doesn't necessarily mean the cell will be editable. Every cell in the grid already uses an editor of one type or another. The editor is just the object that handles the display and editing (if any) of the cell's value.
A DataFilter is actually a good option here. Another option would be to use a DrawFilter (to draw the text yourself), or a CreationFilter (to set the text on the TextUIElement in the cell.
Yes another option would be to hide the "real" grid column, add an unbound column and use the grid's InitializeRow event to read the property of the object you want from the "real" column and populate the unbound column with that value. This is basically the same as using a DataFilter, except the DataFilter doesn't require an extra column. The unbound column method is typically easier to code and understand, but the DataFilter method is more elegant.
In that case, you would have to use a DataFilter instead of a DrawFilter. In this case, you would handle the EditorToDisplay conversion. This will be called any time the grid wants to translate the value of the cell into a string for display.
OK, no this does not work for me, I need the cell to "know" its contents, therefore I still hope there is a way to "intercept" the Grid from just calling ToString().
A DrawFilter allows you to draw into an element in the grid. You can't change the size of the element. If you need the element to be bigger, then you have to change the size of the actual object - the row height or the column width.
Also note that the grid won't know what you drew into the cell. So Auto-sizing the row or column won't be able to take this into account. It will still autosize based on the actual value of the cell.
I really like the idea of the DrawFilter, that is what I want. Only one more thing I don't get - the DrawElement method gets the region where the text can be drawn, I would like to draw text that needs to span multiple lines, how can I get the region to be bigger?