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
I tried this out and I get the same results. The Autosizing appears to be using the Format of the entire column, but ignoring the format on a cell when provided by an editor. This seems to be a bug. I'm going to ask Infragistics Developer Support so create a case for you and write this up for developer review so we can get it fixed.
One thing you could do in the mean time is apply a format to the column. This isn't perfect, but if you use the longest of your three possible formats, it should produce better results than what you have now - which is that the column is way too wide.
Note: ignore the set width lines in the initialize code, that was just added after the failed autosizing.
it should be
if (col.Key == "Format") { col.Hidden = true; } else if (col.DataType.Name == "Decimal") { col.Editor = new EditorWithText(owner); } col.PerformAutoResize(PerformAutoSizeType.AllRowsInBand);
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 } } }
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"; }}