WPF - Getting the value of one a DataGridCell from within DataTemplateSelector

Posted by Andy T on Stack Overflow See other posts from Stack Overflow or by Andy T
Published on 2010-03-26T20:10:32Z Indexed on 2010/03/26 20:13 UTC
Read the original article Hit count: 518

Hi,

I'm using DataTemplateSelector with the WPFToolkit DataGrid. I want to select the editing template for one cell based on the value of another cell on the same row.

The DataTemplateSelector's SelectTemplate method takes two arguments: one is the data item displayed by the grid row, the other is the grid cell.

What I want to know is how to get the value of another cell from within the SelectTemplate method. However, I'm not sure of the correct way to get this information by accessing properties of the cell.

    public class RangeValuesEditTemplateSelector : DataTemplateSelector
{
    public DataTemplate NumberTemplate{get; set;}
    public DataTemplate TextTemplate{get; set;}

    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        //TODO: need to find the correct way to populate the if condition below
        DataGridCell theCell = container as DataGridCell;


        if (theCell.something.somethingElse)
        {
            return NumberTemplate;
        }else{
            return TextTemplate;
        }

    }


}

Can anyone help?

Many thanks in advance.

AT

© Stack Overflow or respective owner

Related posts about wpf

Related posts about datagrid