Menu

Background color row filtered by cell

Help
Anonymous
2012-10-12
2012-10-30
  • Anonymous

    Anonymous - 2012-10-12

    Good afternoon,

    It's being complicated to solve the problem that i am facing.

    I have a ObjectListView filled and need to distinguish the rows that have a
    specific value in a cell.

    So, if the cell as a value of 1 -> yellow row, value of 2 -> orange row, and
    so on..

    I used the default ObjectListView control provided, no code used.

    What is the best way to do that?

    Thank you!

     
  • Phillip Piper

    Phillip Piper - 2012-10-13

    To do this, you'll need to listen to the FormatCell event. This code colours
    the "Cooking Skill" cells depending on the value in the cell.

    this.olvSimple.UseCellFormatEvents = true;
    this.olvSimple.FormatCell += (sender, args) => {
        // Only for the columns you want
        if (args.Column.Text != "Cooking Skill") 
            return;
    
        if (!(args.CellValue is int)) 
            return;
    
        switch ((int)args.CellValue) {
            case 1:
                args.SubItem.BackColor = Color.Aquamarine;
                break;                            
            case 30:
                args.SubItem.BackColor = Color.GreenYellow;
                break;
        }
    };
    

    Regards,
    Phillip

     

Log in to post a comment.

MongoDB Logo MongoDB