views:

308

answers:

2

Hi,

I have a wpf datagrid with many rows, each row has some specific behaviors like selection changed of column 1 combo will filter column 2 combo, and what is selected in row 1 column 1 combo cannot be selected in row 2 column 1 combo, etc...

So I am thinking of having a view model for the main datagrid, and another for each row.

Is that a good MVVM implementation? It is so that I can handle each row's change event effectively.

Question is, how do I create "each row" as a user control view? within the datagrid.

I want to implement something like this:

        <TreeView
        Padding="0,4,12,0">

        <controls:CommandTreeViewItem
            Header="Sales Orders"
            Command="{Binding SelectViewModelCommand}"
            CommandParameter="Sales Orders"/>          

    </TreeView>  

Where instead of a TreeView I want a datagrid, and instead of controls:CommandTreeViewItem a datagrid row in WPF.

Thanks in advance.

A: 

You can use DataTemplate for each row and customize it the way u need.

Johnny
A: 
        <my:DataGrid x:Name="locationGrid">
            <my:DataGrid.Columns>
                <my:DataGridTemplateColumn>
                    <my:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=LocationName}"/>
                        </DataTemplate>
                    </my:DataGridTemplateColumn.CellTemplate>
                    <my:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                            <TextBox Text="{Binding Path=LocationName}"/>
                        </DataTemplate>
                    </my:DataGridTemplateColumn.CellEditingTemplate>
                </my:DataGridTemplateColumn>
            </my:DataGrid.Columns>
        </my:DataGrid>    

You can put in each DataGrid column almost whatever you want. I gave you example here. You can define even header template. If you make small program there is no need for MVVM, but I don't understand you quite well why you need MV for DataGridRow? Make UserControl and embed it in DataTemplate, and for UserControl make VM class.

Levelbit