if i display sql queries result on my wingrid and some or most part of the grid has a zero as a cell value ?can i format the cell to display blank instead the zero or should i need to visit each cell and blank it?
Thanks.
If it is a Interger column then you can set MinValue as 1
ultragrid.DisplayLayout.Bands[0].Columns["ColumnOne"].MinValue =1;
Manoj Kumar said: If it is a Interger column then you can set MinValue as 1 ultragrid.DisplayLayout.Bands[0].Columns["ColumnOne"].MinValue =1;
I don't think that's a good idea. If the user goes into the cell and tries to edit it and then leaves with an empty cell, intended to put a 0 back into the cell, it will raise an exception, since the MinValue is 1.
There's no easy to way to make the cell blank when it's a 0. You would have to use a filter of some kind. Probably the easiest thing to do would be to use a DataFilter to translate a 0 to an empty string and vice versa.
this is what i have at the moment
Private Sub ClearLeadingZeros(ByRef WorkingGrid As UltraGrid, Optional ByVal StartCol As Integer = 0) Dim iCols As Integer = 0 Dim ugRow As UltraGridRow
For Each ugRow In WorkingGrid.Rows.GetRowEnumerator(GridRowType.DataRow, Nothing, Nothing) For iCols = StartCol To WorkingGrid.DisplayLayout.Bands(0).Columns.Count - 1 If ugRow.Cells(iCols).Value.ToString = "0" Then ugRow.Cells(iCols).Value = -1 End If Next Next
End Sub
but would like to blank the cell instead changing value to -1
am i close to my solution?
No, EditorWithTextOwner is not what you need.
It's Infragistics.Win.EditorWithText
hi thanks for you respond
i was able to translate the class from c# to vb net but i have problems with the funtion where i assign the function to the columns
Private Sub UltraGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles UltraGrid1.InitializeLayout Dim editorWT As EditorWithTextOwner
editorWT.DataFilter = New ZeroAsBlankDataFilter() e.Layout.Bands(0).Columns("Column 0").Editor = editorWT
where EditorWithText does not exist but exist EditorWithTextOwner and is especting something, dont know if im correct.
A DataFilter is an interface that allows you to intercept the value as it is transferred from the owner, editor, and display.
Create a class and implement the IEditorDataFilter interface that handles the EditorToDisplay and DisplayToEditor conversions.
In DisplayToEditor, you translate an emprt string or null into a 0.
In EditorToDisplay, you reverse that, translating a 0 into an empty string.
The DataFilter might looks something like this:
public class ZeroAsBlankDataFilter : IEditorDataFilter { #region IEditorDataFilter Members object IEditorDataFilter.Convert(EditorDataFilterConvertArgs conversionArgs) { switch (conversionArgs.Direction) { case ConversionDirection.DisplayToEditor: if (conversionArgs.Value is DBNull || conversionArgs.Value == null || conversionArgs.Value.ToString().Length == 0) { conversionArgs.Handled = true; return 0; } break; case ConversionDirection.EditorToDisplay: if (conversionArgs.Value is int && ((int)conversionArgs.Value) == 0) { conversionArgs.Handled = true; return null; } break; } return conversionArgs.Value; } #endregion }
And you assign it to the grid like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { EditorWithText editorWithText = new EditorWithText(); editorWithText.DataFilter = new ZeroAsBlankDataFilter(); e.Layout.Bands[0].Columns["Column 0"].Editor = editorWithText; }
You can create a single EditorWithText and assign it to as many columns as you like.