Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Conditional formatting

Sort Posts: Previous Next
  •  07-18-2008, 9:59 AM Post no. 13618

    Conditional formatting

    How to implement coditional formatting in Xceed Grid (i.e. changing row back color based on some cell value)? Solutions that I found involved using AddingDataRow event, but I don't find this to be best - they require handling reformatting of existing rows on data modification by hand. I'm sure, there is a neat solution for this problem - even DataGridView control has it.

     I can do something like it there (in DataGridView) to change cell forecolor:

    private void LoginHistoryDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

    {

    if (LoginHistoryDataGridView.Columns[e.ColumnIndex].Name.Equals("actionDataGridViewTextBoxColumn"))

    {

    switch ((int)((DataRowView)LoginHistoryDataGridView.Rows[e.RowIndex].DataBoundItem).Row["ActionId"])

    {

    case 0:

    e.CellStyle.ForeColor = Color.Green;

    break;

    case 1:

    e.CellStyle.ForeColor = Color.Blue;

    break;

    case 2:

    e.CellStyle.ForeColor = Color.Red;

    break;

    }

    }

    }

    So, I'd like to have something like this in Xceed Grid.

    Thanx in advance!

  •  07-18-2008, 11:51 AM Post no. 13628 in reply to 13618

    Re: Conditional formatting

    You can use the ValueChanged event on DataCell to do this, which will work both at startup and on existing rows.

    e.g.:

    private void Form1_Load( object sender, EventArgs e )

    {

        dataRowTemplate1.Cells[ "SupplierID" ].ValueChanged += new EventHandler( Form1_ValueChanged );

    }

    void Form1_ValueChanged( object sender, EventArgs e )

    {

        DataCell cell = sender as DataCell;

        if( cell != null )

        {

            if( ( int )cell.Value == 3 )

            {

                cell.ForeColor = Color.DeepPink;

            }

        }

    }

     


    André
    Software Developer and Tech Support
    Xceed Software Inc.
  •  07-18-2008, 3:34 PM Post no. 13634 in reply to 13628

    Re: Conditional formatting

    Nice, thanks a lot!

     In fact I'm new to Xceed components and a bit confused with hundreds of properties/events :)

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.