Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
275
Setting inividual CellValuePresenter properties
posted

I've been trying to create a method that sets a particular cell to readonly (along with changing the background color).  I want something like:

public void SetCellToReadOnly(int rowIndex, int columnIndex) {
        ((DataRecord)myXamDataGrid.Records[rowIndex]).Cells[columnIndex].ReadOnly = true;
        ((DataRecord)myXamDataGrid.Records[rowIndex]).Cells[columnIndex].Background = Brushes.Grey;
}

What would be the easiest way to achieve this?

Thank you,
Mike

  • 275
    Verified Answer
    posted

    I figured it out - here is the end result if anyone wants to know:

    private Brush readOnlyColor = (Brush)new BrushConverter().ConvertFrom("#EEEEEE");//Light shade of gray
    public void SetCellToReadOnly(int rowIndex, string columnName) {
        CellValuePresenter.FromCell(((DataRecord)myXamDataGrid.Records[rowIndex]).Cells[columnName]).IsEnabled = false;
        CellValuePresenter.FromCell(((DataRecord)myXamDataGrid.Records[rowIndex]).Cells[columnName]).Background = readOnlyColor;
    }

    Mike