Home Forums WinForms controls Xceed Grid for WinForms forecolor in column depending on the value of data

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

    Hello,

    First post here. I am studying this excellent grid control.
    One thing I regularly used earlier, coloring a column depending on the data. For example I highlight negative values, or hide zero values.
    How is this possible with this grid?

    Regards

    Imported from legacy forums. Posted by szinkopa (had 2927 views)

    User (Old forums)
    Member
    Post count: 23064

    Each visual element in the grid (Row, Column, Cell, …) has some visual properties you can set (BackColor, ForeColor, Font, …)
    To make the color depend on the data, you’ll have to catch the ValueChanged-event of the cell, and set the color there.<code>grid.DataRowTemplate.Cells[“myCell”].ValueChanged += new EventHandler(myCell_ValueChanged);
    private void myCell_ValueChanged(object sender, EventArgs e)
    {
    Cell cell = sender as Cell;
    if (…cell.Value…) // here you set your condition
    cell.ForeColor = Color.Red;
    else
    cell.ResetForeColor();
    }</code>

    Imported from legacy forums. Posted by Tommy (had 286 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you Tommy, that’s really good. Do I have to do it for every cell? I guess no, because this is the template row.
    Does the desinger support automatic code generation for event subscription?

    Imported from legacy forums. Posted by szinkopa (had 351 views)

    User (Old forums)
    Member
    Post count: 23064

    If you use the Windows Forms Designer, you can click on a cell in the template row to select it, and on the Events-panel you can subscribe to events for that cell.

    Imported from legacy forums. Posted by Tommy (had 4004 views)

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