I'm trying to format a column in my UltraWinGrid and seem to be stuck. The data that is bound is a string that contains only numbers (i.e. 262546500 or 1004344131). I would like this to be formatted with a dash before the last two numbers (i.e. 2625465-00 or 10043441-31). Is there a way i can do this, no amount of mask formatting seems to product the effect i'm looking for
Note that my data can be either be 9 or 10 characters long but there should always be a dash displayed before the last two characters. I do not want the underlying data changed, only the way it's displayed.
I have experimented using a variety of MaskInput values (even though i'm not inputting anything, only displaying) but the fact that there are either 9 or 10 characters seems to be causing a problem. What works for a length of 9 fails for 10, and so on. It seems as if the mask works from left to right but i'm not sure if that is the problem.
In case you are wondering, the reason it affects all columns is that the grid shares the same editor amongst all the columns it can by default. This is done for efficiency. So the solution is, as you discovered, to assign a different editor to the columns you need. :)
I figured it out. I just had to give that column a different editor and change a few things here and there.
Thanks for the help everyone, it made a big difference.
Thanks for all of the replies. The datafilter idea seems to be the way i should go. The KB article's code implements it a bit differently though.
I wrote the class for the datafilter but i'm not sure i'm putting it in the right place. I'm basically making a call like this:
e.Layout.Bands["BandName"].Columns["ColumnName"].Editor.DataFilter = new mytestdatafilter()
For a test my data filter just returns a string with appended values.
I see it firing (by setting a breakpoint) but it fires for all columns, not just the one i applied the filter one. I'm wondering if all of the text boxes in the grid are using the same data filter. Is there a way to break that so it only fires for the column i want? Also, the values i'm returning are not showing up in the grid.
The Format property of the grid works by calling the ToString method of the cell's Value and passing in the format. The string data type in DotNet does not support any formats, so Format will never have any effect on a string column. So you will either need to change the column to a numeric type or you can use a DataFilter, as BarraCoder suggested.
But if you want to save the data without the dash, it might be easier just to use a DataFilter. There's a decent kb article on DataFilters at http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=4877 and another one on bools which is useful.