Hi
Is there a cell level property using which i can apply formats to a value for a particular cell?
I have grid(dynamic grid using ultradatasource) such that there are predefined formats(e.g. percentage,currency etc) to be applied to values for some cells within a column.
In the forums i can find ways to apply format for a complete column but that is not useful in my case.
Normal 0 false false false EN-US X-NONE X-NONE
TYPE
VALUE
a
<dollar>
b
<percentage>
The best way to solve this problem is to use a DefaultEditorOwner when you create the editor that you assign to the UltraGridColumn.Editor property. This class derives from the class that we use to abstract out the communication layer between the editor and the grid. In your case you would derive a class from DefaultEditorOwner, override the GetFormat method, and pass an instance this derived class into the constructor of the editor you assign to the UltraGridColumn.Editor property.
The signature of the GetFormat method (like most of the virtual methods exposed by this class) contains an 'ownerContext' parameter; this is either the UltraGridCell or a CellUIElement, and if I remember, can also be an UltraGridRow as well, although you can ignore that case and just call the base class implementation. Once you get a context of a cell, you decide what format you want to apply, then assign that format to the out parameter of the same name. In this manner, you can apply a different format to each cell in that column dynamically.
Can you please provide a simple code example for that(vb.net)?
Thanks
I just took a look and it looks like I was wrong and this always worked.
But I noticed that the Format and the FormatInfo properties on the column will override the properties on the editor. So be sure you are not setting these properties on the column.
If that still doesn't help, see if you can duplicate the problem in a small sample project and post it here (you can attach a file under the Options tab) and I will be happy to take a look and see why it's not working.
We are not setting the format property at column level.
As we have to apply different formats to different cells,whose row index and column index are dynamically generated,we have created a function using your example which will be called every time we are changing the value of a cell & used the code written in "InitializeRow" event of your example.
But still its not working.Any suggestion?
The attached sample demonsrates how to apply a different format for each cell in a column without assigning a different editor to each cell (that approach is inefficient because if you have lots of cells you will be creating lots of editors). In this example, a column which contains currency values is assigned a custom EmbeddableEditorOwnerBase implementation which overrides the GetFormatInfo method; this is the method the cells use when obtaining the formatting information from the grid.
Can you give this FormatByCell.zip example in VB .net
Thanks.
Hello webd,
The code you could use for this(should be in Form1.vb's WinGrid InitializeRow event) is:
Dim numberOfDecimalPlaces As Integer = CInt(e.Row.Cells("NumberOfDecimalPlaces").Value) Dim format As String = "#.#" If numberOfDecimalPlaces > 1 Then format += New String("0"C, numberOfDecimalPlaces - 1) End If
Dim defaultEditorOwnerSettings As New DefaultEditorOwnerSettings() defaultEditorOwnerSettings.Format = format Dim defaultEditorOwner As New DefaultEditorOwner(defaultEditorOwnerSettings) Dim editorWithText As New EditorWithText(defaultEditorOwner) e.Row.Cells("Value").Editor = editorWithText
Please do not hesitate to contact me if you need any additional assistance.
I've been trying variations of the code posted on this subject in this as well as several other postings without success and have found a caveat (at least in version 10.1) that will keep the format from ever updating. If you ever had a format in the column entered via the editor and remove it, it doesn't actually remove the format line and always overrides what you do with a blank format. I had to delete the line from the designer to get it to work.
Example (from designer):
Before:
ultraGridColumn22.Format = "C2";
After:
ultraGridColumn22.Format = "";
Okay, as long as bPercent is a value based on something in e.Row, then I don't see anything wrong with this code. If you could post a small sample project demonstrating the issue, I would be happy to take a look at it, but otherwise, I don't see any reason why this should not work.
bPercent is set based off a date value on that row. I was setting its value just before the code.
They want all old records to be formatted $ and new records formatted %. I have a record created date in each record.
Sorry I simplified my code because I have to change 4 fields based on this.
I did not get this line included in the example code.
I can mock up an example but it will work sometimes and seems based off lots of data. When it does not format there is no format at all.
Hi,
What is bPercent here? It looks like you are using some form-level variable to determine which format to use, but that doesn't make sense. You need to use some information on the row itself. Otherwise, you will be assigning formats to the row pretty much at random.
I am not able to catch what is happening here so could you please wrap this scenario in a small sample project which reproduces the behavior and attach it here.