How to: Apply Conditional Formatting to Grid Cells using the Bar Format Condition

  • 2 minutes to read

The Bar format condition (FormatConditionBar) allows you to visualize numeric values using bars.

This example shows how to display data bars within grid cells. Note that bars corresponding to positive and negative values are colored differently.

View Example

Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin

Namespace Grid_IconRangeCondition
    Partial Public Class Form1
        Inherits DevExpress.XtraEditors.XtraForm

        Public Sub New()
            Dim dashboard As New Dashboard()
            dashboardViewer1.Dashboard = dashboard
            Dim grid As GridDashboardItem = CType(dashboard.Items("gridDashboardItem1"), GridDashboardItem)
            Dim extendedPrice As GridMeasureColumn = CType(grid.Columns(1), GridMeasureColumn)

            Dim barRule As New GridItemFormatRule(extendedPrice)
            Dim barCondition As New FormatConditionBar()
            barCondition.StyleSettings = New BarStyleSettings(FormatConditionAppearanceType.PaleBlue)
            barCondition.NegativeStyleSettings = New BarStyleSettings(FormatConditionAppearanceType.PaleRed)
            barCondition.BarOptions.AllowNegativeAxis = checkBox1.Checked
            barCondition.BarOptions.DrawAxis = True
            barRule.Condition = barCondition

        End Sub

        Private Sub checkBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles checkBox1.CheckedChanged
        End Sub

        Private Sub checkBox2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles checkBox2.CheckedChanged
        End Sub

        Private Sub checkBox3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles checkBox3.CheckedChanged
        End Sub

        Private Sub UpdateBarOptions()
            Dim grid As GridDashboardItem = CType(dashboardViewer1.Dashboard.Items(0), GridDashboardItem)
            Dim barOptions As FormatConditionBarOptions =
                CType((grid.FormatRules(0)).Condition, FormatConditionBar).BarOptions
            barOptions.AllowNegativeAxis = checkBox1.Checked
            barOptions.DrawAxis = checkBox2.Checked
            barOptions.ShowBarOnly = checkBox3.Checked
        End Sub
    End Class
End Namespace
See Also