Home Forums WinForms controls Xceed Grid for WinForms Current Cell BackColor

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

    Hey Everyone –

    I’m having trouble working with the CurrentCellChanged event. I’d like to have the backcolor of the current cell be a different color than the rest of the row, and to do so I’m using a very slightly modified version of the following:

    protected void Grid_CurrentCellChanged(object sender, EventArgs e)
    {
    GridControl mGrid = (GridControl)sender;
    if (mGrid != null && mGrid.CurrentCell != null)
    {
    if (cell.IsCurrent)
    {
    cell.BackColor = _selectedColor;
    }
    else
    {
    cell.ResetBackColor()
    }
    }
    }

    Unfortunately, it seems as if the gridcontrol’s SelectionBackColor color is overriding the color set in the above method. When the current cell changes, for a split second I can see that its back color has changed to the _selectedColor, but then it (and all the other cells in its row) immediately changes to the SelectionBackColor. Any suggestions?

    Thanks in advance.

    Craig

    Imported from legacy forums. Posted by csperler (had 2990 views)

    User (Old forums)
    Member
    Post count: 23064

    Sorry… missed a line copying over…

    protected void Grid_CurrentCellChanged(object sender, EventArgs e)
    {
    GridControl mGrid = (GridControl)sender;
    if (mGrid != null && mGrid.CurrentCell != null)
    {
    Cell cell = mGrid.CurrentCell;
    if (cell.IsCurrent)
    {
    cell.BackColor = _selectedColor;
    }
    else
    {
    cell.ResetBackColor()
    }
    }
    }

    Imported from legacy forums. Posted by csperler (had 320 views)

    User (Old forums)
    Member
    Post count: 23064

    If you say <i>cell = mGrid.CurrentCell</i>, isn’t <i>cell.IsCurrent</i> always true? I think you should call ResetBackColor on the previous CurrentCell, and change the BackColor of the new CurrentCell, something like this:<code>private Cell mCurrentCell = null;
    protected void Grid_CurrentCellChanged(object sender, EventArgs e)
    {
    GridControl grid = sender as GridControl;
    if (grid != null && mCurrentCell != grid.CurrentCell)
    {
    if (mCurrentCell != null) mCurrentCell.ResetBackColor();
    mCurrentCell = grid.CurrentCell;
    if (mCurrentCell != null) mCurrentCell.BackColor = _selectedColor;
    }
    }</code>I don’t know if this will solve your problem.

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

    User (Old forums)
    Member
    Post count: 23064

    (Thanks for the quick response Tommy.)

    I’ve created a grid, added a few columns, populated the grid with data, and set up the following event:

    private void gridControl1_CurrentCellChanged(object sender, System.EventArgs e)
    {
    GridControl mGrid = sender as GridControl;
    mGrid.CurrentCell.BackColor = Color.Red;
    }

    When I select a new cell, that cell’s whole row is painted blue, when I select a different cell, the previous current cell is painted red. This leads me to believe that the current cell is being colored correctly but the row selector bar is somehow sitting on top of the row’s backcolor… if that makes sense.

    Anyone have any suggestions?

    Thanks.

    Craig

    Imported from legacy forums. Posted by csperler (had 4198 views)

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