1
votes

We have an observable collection that consists of a custom class called Row which is used as itemsource in our Datagrid. The Row class itself consists of 3 different cell types.

public class Row
{

    public TimeCell TimeCell { get; set; }
    public PositionsCell PositionsCell { get; set; }
    public TemperatureCell TempCell { get; set; }
}

These cell types all have the parent class Cell which contains the majority of properties. Our Datagrid consists of template columns representing each of the cells in Row with relevant bindings. The problem is that when we do Datagrid Selecteditem we currently get a Model.Row returned whereas we would like to get the cell directly (Model.Row.TimeCell) for example if a cell in that column was clicked/selected. How can we achieve this?

1
Check the currentcell property of datagrid will give u what u expect. - neelesh bodgal
Checking currentcell gives Controls.DatagridCellinfo, checking currentcell.item gives the same as datagrid selecteditem - DreeAudoLow
Had a look in that post and tested everything, nothing works. One of the answers states it doesnt work with datagridtemplatecolumns. - DreeAudoLow
Set DataGrid.SelectionUnit to DataGridSelectionUnit.Cell. Using this configuration, DataGrid.SelectedCells will return the currently selected cells. - BionicCode

1 Answers

0
votes

You Need to cast DataGrid.SelectedItem To your custom class item i.e.

Row selRow = mainDataGrid.SelectedItem as Row;

Now you can able to access properties of Row i.e.

TimeCell timeCell = selRow.TimeCell;

Hope this will work

Thanks for letting us help you