We are using UltraWinTree with ViewStyle OutlookExpress and a RootColumnSet.
In a column with decimal values and format "N0", we would like to use the Format "N1" for a single (special) row.
One of our trees is readonly. In another tree some cells of this column in some rows are editable, but not in the special row.
Is it possible to control the format for a single cell without having to use "N1" for the whole column?
Hi,
Thank you for posting in our forums.
What you could do in order to achive different formats within the same column is to assign a text editor to the column’s editor property and then create a custom DataFilter for this editor. This will allow you to format the columns based on your needs. For more information on DataFilters please visit this link:
http://help.infragistics.com/Help/Doc/WinForms/2011.2/CLR2.0/html/WinGrid_Using_the_IEditorDataFilter_Interface_with_WinGrid.html
I have attached a sample that demonstrates this approach. It takes the formats from the “Format” column and applies them to the cell “Number” column.
Please let me know if you have any additional questions.
Hi Dimitar
Thank you for your advice and providing sample.
In the meantime I tried a FormatProvider that checked the numbers floor against the number and formatted as N0 or N1. It mostly worked ok, but seemed a bit shaky, as I could not find a way to access the current row, cell or node and determine with surety the special format.
So your solution is much better for us, as we can determine the node and access all its properties.
That was it...
Thank you for helping us promptly!
This is just a small error in the DataFilter code. It should not be returning the raw float value from the EditorToDisplay conversion. This should always return a string. So just change:
if (cellUIElement == null) { return conversionArgs.Value; }
to:
if (cellUIElement == null) { return conversionArgs.Value.ToString(); }
With the custom data filter we now get exceptions, e.g., when resizing the decimal column (double click on right end of Header). This is only in the columns with the custom data filter in an EditorWithText.
Is there something missing in the custom data filter? Or in the EditorWithText?
Stacktrace:
System.InvalidCastException: Das Objekt des Typs "System.Decimal" kann nicht in Typ "System.String" umgewandelt werden. bei Infragistics.Win.EmbeddableEditorBase.GetTextSizeOfValue(EmbeddableEditorOwnerBase owner, Object ownerContext, Boolean allowMultiline, Int32 maxWidth, Boolean isTooltip) bei Infragistics.Win.EditorWithText.InternalGetSize(EmbeddableEditorOwnerBase owner, Object ownerContext, Boolean valueOnly, Boolean full, Boolean includeBorders, Int32 maxTextWidth, Boolean allowMultiline, Boolean includeOwnerPadding, Boolean isTooltip) bei Infragistics.Win.EditorWithText.GetSize(EditorSizeInfo& sizeInfo) bei Infragistics.Win.EmbeddableEditorBase.GetSize(EmbeddableEditorOwnerBase owner, Object ownerContext, Boolean valueOnly, Boolean full, Boolean borders) bei Infragistics.Win.UltraWinTree.ColumnSetLayoutManager.GetCellWidth(UltraTree treeControl, UltraTreeNode node, UltraTreeNodeColumn column, Boolean hasExpansionIndicator) bei Infragistics.Win.UltraWinTree.ColumnSetLayoutManager.PerformAutoResize(UltraTreeNodeColumn column, UIElement element, ColumnAutoSizeMode autoSizeMode) bei Infragistics.Win.UltraWinTree.UltraTreeNodeColumn.PerformAutoResizeHelper(UIElement element, ColumnAutoSizeMode autoSizeMode) bei Infragistics.Win.UltraWinTree.UltraTreeNodeColumnHeaderUIElement.OnDoubleClick(Boolean adjustableArea) bei Infragistics.Win.ControlUIElementBase.ProcessDoubleClick(Object sender, EventArgs e) bei Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e) bei Infragistics.Win.UltraControlBase.OnDoubleClick(EventArgs e) bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Thank you for your feedback.
Do not hesitate to contact us if you have any additional questions.