Hi,
I've a wingrid with a column, type numeric. In InitializeLayout-event I write 'NumCol.Format = "N0"'. But in some rows of this column I need 'Format="N2"'. Is this possible ?
I'm using Infragistics 7.3
Thanks
Hansjörg Wintermantel
The following code sample demonstrates how to use an EmbeddableEditorOwnerBase-derived class which overrides the GetFormatInfo method to format cells differently in every other row:
DefaultEditorOwnerSettings settings = new DefaultEditorOwnerSettings();MyDefaultEditorOwner owner = new MyDefaultEditorOwner();this.ultraGrid1.DisplayLayout.Bands[0].Columns["whatever"].Editor = new EditorWithText( owner );
public class MyDefaultEditorOwner : DefaultEditorOwner{ public override void GetFormatInfo(object ownerContext, out string format, out IFormatProvider provider) { provider = null;
CellUIElement cellElement = ownerContext as CellUIElement; UltraGridColumn column = cellElement.Column; UltraGridRow row = cellElement.Row;
if ( (row.Index % 2) == 0 ) format = "N0"; else format = "N2"; }}
I am using this method to format various rows in a column differently. It works except for one thing: PerformAutoResize does not work, it resizes the column as if there was no formatting. Note, I am ignoring your line "DefaultEditorOwnerSettings settings = new DefaultEditorOwnerSettings();" since the settings variable is not used.
Below is my code:
private void ugResults_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { try { int DefaultWidth = 100; MyDefaultEditorOwner owner = new MyDefaultEditorOwner(); if (e.Layout.Bands[0].Columns.Exists("Format")) { foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn col in e.Layout.Bands[0].Columns) { if (col.Key == "Format") { col.Hidden = true; } else if (col.DataType.Name == "Decimal") { //row.Cells[col.Index].Editor = new EditorWithText(owner); col.Editor = new EditorWithText(owner); col.Width = DefaultWidth; } col.PerformAutoResize(PerformAutoSizeType.AllRowsInBand); } } } catch (Exception ex) { _mainform.HandleException(ex); } } } public class MyDefaultEditorOwner : DefaultEditorOwner { public override void GetFormatInfo(object ownerContext, out string format, out IFormatProvider provider) { format = ""; provider = null; try { CellUIElement cellElement = ownerContext as CellUIElement; if (cellElement.IsNull() == false) { UltraGridColumn column = cellElement.Column; UltraGridRow row = cellElement.Row; switch (row.Cells["Format"].Value.ToString()) { case "Money": format = "#,##0"; break; case "Decimal": format = "#,##0.0000"; break; case "Percent": format = "0.00%"; break; default: format = ""; break; } } else { format = ""; } } catch (Exception) { //eat } } }