Is it possible to use different formatting settings for the data displayed by a bound UltraTextEditor when it is being viewed and when it is being edited?
The behaviour I am particularly looking for in this instance is similar to Excel, where a number is shown with a pre-configured number of decimal places with comma separators when it isn't being edited, but switches to show all of the decimal places and no commas when the user is editing the value.
I suppose what I really want to be able to do is to set the .Net String.Format property for the data in the control separately depending on whether the control is in View or Edit state.
I have worked through this post http://forums.infragistics.com/forums/t/6140.aspx, but like that guy I don't really want to use a masked control as I don't want a fixed number of decimal places when editing (just when viewing). I tried the suggestion there of creating a data filter, but that only works on what is displayed when you are viewing, the mask takes over when you are editing and so you are stuck with a fixed number of decimal places again.
I suppose one option is to roll my own control based on two UltraTextEditors inside a UltraControlContainerEditor; that would allow me to use two datafilters, one for the Edit text editor and one for the view text editor, and to set the different formats for data in the text editors via those datafilters.
That might work, but it seems a long way round, is there an easier way?
Hi,
redox said:First, there is no Format property on a vanilla UltraTextEditor is there? (I got that from here http://news.infragistics.com/forums/p/6063/26556.aspx )
Oh, yes, you are correct. The UltraTextEditor deals with strings, which don't support any formatting in DotNet, so it cannot format for you.
You have a lot of very specific requirements here, so it seems to me that you will have to use a DataFilter to achieve what you want, since that's the only way you will have enough control over the behavior.
redox said:I also really want to define a view format that says "If there are two or less decimal places, then show 2dp, if there are more then show them all" which is something that can be done with .net formatting, but I don't think that can be done with the Infragistics style formatting strings? I think the Infragistics formatting strings are different to the .net ones?
Generally, we don't do any formatting. When you apply a format to something, the Infragistics controls just call the ToString method of the value and pass in the Format. So the Infragistics format strings are exactly the same as the DotNet format string. But it's probably a moot point, since there's no Format property on UltraTextEditor and you want finer control over the behavior anyway.
redox said:Second: The value I'm binding to is a Decimal with 18 decimal places. Depending on how I bind the control and which control I use I keep getting all 18 of the decimal places when I start editing the data (this only occurs after I have round-tripped the data to and from SQL Server). That was what made me think I need to be able to format the edit mode as well as the view mode as I could use a format to knock off the superfluous trailing zeros.
You lost me a little bit here. If round-tripping the data to SQL Server is changing how it displays, then something is wrong. What's the data type of the field in SQL Server you are binding to? The only way I can see this happening is if you are binding the Text property of the control to a string field and using a DataFilter to change the string ends up updating your data source to include the zeroes.
It's generally not a good idea to store numeric values are strings, since this will cause all sorts of problems with sorting, filtering, and formatting.
Assuming your field in SQL Server is a decimal field, then you should be able to achieve what you want using the DataFilter and handling only the EditorToOwner and OwnerToEditor transitions.
In EditorToOwner you will have to take the string and convert it to a decimal. In OwnerToEditor, you reverse it, converting the decimal value into a formatted string in whatever format you like.
The only tricky part is using a different format based on whether the control is in edit mode or not. So your DataFilter will have to know this. You could just create a property on the DataFilter class and set this property when the UltraTextEditor enters or exits edit mode, then you use that property to determine which format to use whenever the OwnerToEditor transition fires.
Hi Mike, thanks for the speedy response. There are a couple of issues I'm having:
First, there is no Format property on a vanilla UltraTextEditor is there? (I got that from here http://news.infragistics.com/forums/p/6063/26556.aspx )
To get round that I have set the format via Properties Pane->Data Bindings->Advanced. That formatting then gets applied to both the View and Edit state - presumably because this is being done before the control gets the data? That's not the behaviour I need because it means that the reduced number of decimal places and comma separators are still there when the user edits.
(That only works at all if I bind the UltraTextEditor's Text property rather than its Value property.)
Obviously the UltraNumericEditor has a FormatString property, but the UltraNumericEditor requires you to define a fixed number of decimal places via the mask I believe, so I can't use it.
I also really want to define a view format that says "If there are two or less decimal places, then show 2dp, if there are more then show them all" which is something that can be done with .net formatting, but I don't think that can be done with the Infragistics style formatting strings? I think the Infragistics formatting strings are different to the .net ones?
Second: The value I'm binding to is a Decimal with 18 decimal places. Depending on how I bind the control and which control I use I keep getting all 18 of the decimal places when I start editing the data (this only occurs after I have round-tripped the data to and from SQL Server). That was what made me think I need to be able to format the edit mode as well as the view mode as I could use a format to knock off the superfluous trailing zeros.
I must be missing something.
The Format property of a cell only applies when that cell/control is not in edit mode. So it seems to me that if you use a format that limits the number of decimal places displayed and also shows the digit grouping separators (commas), then that's all you need to do. When the cell/control enters edit mode, the user will see the raw data without the separators and including all of the digits.
So... what's giving you trouble here?