Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
200
In UltraGrid columns with datatype float/Int should display blank insted of 0
posted

 

Hi,

I am novice Infragistics developer.

I have a basic question,As per our business requirement we need to show "BLANK" value for all the float/Int columns having value "0"

How can this be accomplished with UltraGrid?

Thanks,

Shashank

 

  • 990
    posted

    I would use a custom format provider for this.

    Firstly, create a provider class:

    Public Class NumberFormatProvider : Implements IFormatProvider, ICustomFormatter

        Public Function GetFormat(ByVal formatType As System.Type) As Object Implements System.IFormatProvider.GetFormat
            If (formatType Is GetType(ICustomFormatter)) Then
                Return Me
            Else
                Return Nothing
            End If
        End Function

        Public Function Format(ByVal fmt As String, ByVal arg As Object, ByVal formatProvider As System.IFormatProvider) As String Implements System.ICustomFormatter.Format
            Try
                If (arg.GetType() IsNot GetType(Integer)) Then
                    Return ""
                Else
                    Dim value As Integer = DirectCast(arg, Integer)
                    If (value = 0) Then
                        Return "BLANK"
                    Else
                        Return value.ToString(fmt)
                    End If
                End If
            Catch ex As Exception
                Return ex.Message
            End Try
        End Function

    End Class

    Then, set your column properties to use it:

            Dim column As Infragistics.Win.UltraWinGrid.UltraGridColumn = UltraGrid1.DisplayLayout.Bands(0).Columns("Amount")
            column.Format = "$ #.##"
            column.FormatInfo = New NumberFormatProvider()

    This should work for Integers, you'll need to modify it to also work with floats.

    This is obviously VB.NET as that's the project I had open at the time. If you need a C# version let me know.

    Cheers,

    Andy.

  • 37774
    posted

    If you actually want to show "BLANK" in the cell instead of 0, you have two options.  The first is to use a DataFilter, examples of which can be found in the Knowledge Base.  Your other options is to create an unbound string column and to hide the real column; in the InitializeRow event you would copy over the values from the real column to the unbound one, adding "BLANK" instead of 0 when you encounter it.  Of course, the downside to the latter approach is that since you have a string column, you lose some of the benefits of dealing with a strictly numeric type; you might be able to work around that by using a numeric mask input on the column.

    -Matt

  • 395
    posted
    Hi, Please try this Grid.Rows.ColumnFilters["ColumnName"].FilterConditions.Add (Infragistics.Win.UltraWinGrid.FilterComparisionOperator.NotEquals, (DataType)Value);