Welcome to the Xceed Community | Help
Community Search  
More Search Options

Changing Cell background

Sort Posts: Previous Next
  •  05-10-2012, 10:13 PM Post no. 32096

    Changing Cell background

    Dear Xceed WPF datagrid experts, 

    I am struggling with the WPF datagrid cell background changes. I used the following code but in result it shows something else,

    If I select one cell to change the BG, say rowIndex=2, colIndex=3, and the in the spread in the same column (colIndex:3) multiple randomly row got marked. where I wanted only selected.

    please update me if write any wrong code.

    System.Collections.Generic.IList<SelectionCellRange> selItems = dataSpreadView.OrdersGrid.SelectedCellRanges;

    foreach (var selectionCellRange in selItems)

    {

    int colIndex = selectionCellRange.ColumnRange.StartIndex;

    int rowIndex = selectionCellRange.ItemRange.StartIndex;

    DataRow dr = dataSpreadView.OrdersGrid.GetContainerFromIndex(rowIndex) as DataRow;

    dr.Cells[colIndex].Background = System.Windows.Media.Brushes.Red;

    }

    Filed under:
  •  05-11-2012, 10:40 AM Post no. 32097 in reply to 32096

    Re: Changing Cell background

    Hi Parth,

    The problem is that you are setting the background color directly on a specific DataCell. However, we use cell recycling, meaning cells that are moved out of view while scrolling or re-used to display the new ones. This is used to improve memory usage (instead of creating fresh new cells every time).

    Instead you should do something like use a Style on DataCell that uses Triggers to change the Background color of the correct DataCells only.

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


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