Set Column forecolor at run-time in c1gridview base on column value

Posted by: dtrgs-net on 10 September 2017, 11:35 am EST

  • Posted 10 September 2017, 11:35 am EST

    I'm trying to achieve 'conditional formatting' based on the value of a column in the c1gridview web control.


    Example, if the column has a negative value, set the fore color to red otherwise set to green.


    Does anyone have an example of this?


    Thanks

  • Replied 10 September 2017, 11:35 am EST

    Hi,


    you can create the OnRowCreated event handler and change the fore color of needed cell. A data object bound to the row being created is passed as e.Row.DataItem


    For example,


        void C1GridView1_RowCreated(object sender, C1GridViewRowEventArgs e)
        {
            if (e.Row.RowType == C1GridViewRowType.DataRow)
            {
                if ((int)((DataRowView)e.Row.DataItem)["Quantity"] < 5)
                {               
                      e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;
                }
            }
        }

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels