Home Forums WinForms controls Xceed Grid for WinForms Conditional formatting

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16289 |

    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!

    Imported from legacy forums. Posted by Nazar (had 1270 views)

    User (Old forums)
    Member
    Post count: 23064

    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;

            }

        }

    }

     

    Imported from legacy forums. Posted by André (had 413 views)

    User (Old forums)
    Member
    Post count: 23064

    Nice, thanks a lot!

     In fact I’m new to Xceed components and a bit confused with hundreds of properties/events 🙂

    Imported from legacy forums. Posted by Nazar (had 928 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.