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
705
controlling individual cell format
posted

I have a grid with a column that is taking user numeric input.  A selection the user makes from a drop down list controls how that input is formatted.  Currently, their two options are "Amount" and "Percent".  If they select amount I want the current active cell to have regular number currency formatting as if I were to set the whole column like this:

myUltraGrid.DisplayLayout.Bands[0].Columns["AGV_AMOUNT"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Currency;

If they select percent I want the current active cell to have formatting as if I were to set the whole column like this:

agUltraGridGuarantors.DisplayLayout.Bands[0].Columns["AGV_AMOUNT"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.IntegerNonNegative;

Is there a way to do this?

  • 1210
    Verified Answer
    Offline posted

    You are on the right track, just do it on cell level rather than column level. You can either place your code in Initialize row and then force the row to initialize when the entry type is changed (myUltraGrid.ActiveRow.Refresh(UltraWinGrid.RefreshRow.FireInitializeRow)) , or have an internal method  called on InitializeRow and when the entry type is changed.

    The example below is vb, but it should be easy to change this to C#:

        Private Sub myUltraGrid_InitializeLayout(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles myUltraGrid.InitializeLayout
            Dim valList As New Infragistics.Win.ValueList
            valList.ValueListItems.Add("Amount")
            valList.ValueListItems.Add("Percent")
            e.Layout.Bands(0).Columns("EntryType").ValueList = valList
        End Sub

        Private Sub myUltraGrid_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles myUltraGrid.InitializeRow
            SetCellStyle(e.Row)
        End Sub

        Private Sub myUltraGrid_CellChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles myUltraGrid.CellChange
            If e.Cell.Column.Key = "EntryType" Then
                SetCellStyle(e.Cell.Row)
            End If
        End Sub

        Private Sub SetCellStyle(ByVal row As UltraWinGrid.UltraGridRow)
            If row.Cells("EntryType").Value = "Amount" Then
                row.Cells("AGV_AMOUNT").Style = UltraWinGrid.ColumnStyle.Currency
            Else
                row.Cells("AGV_AMOUNT").Style = UltraWinGrid.ColumnStyle.IntegerNonNegative
            End If
        End Sub

     

    Trausti