Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I currently have a DataGrid which is populated by a list using DataGrid.DataContext = list

My issue is that i need to edit these values in a seperate WPF window. I've read many articles about in-line editing, but not much on populating the table from another window.

The edit window will have OK and Cancel buttons, and should only mirror the changes back to the datagrid on the OK command. The secondary window should also be populated with the selected row's values. Can provide code so far if necessary.
Posted

1 solution

i hope your main window contain DataGrid .
create a datatemplate
XML
<datatemplate x:key="DataTemplateBaseChargeSetting" xmlns:x="#unknown">
                <border borderthickness="1">
                          BorderBrush="Transparent"
                          CornerRadius="2"                          
                          HorizontalAlignment="Stretch"
                          Margin="2">                   
                    
                    <border borderbrush="Black">
                            BorderThickness="1"
                            CornerRadius="3"
                            Margin="2">
                        <grid>
                        <grid.columndefinitions>
                            <columndefinition width="auto" />
                            <columndefinition width="auto" />
                            <columndefinition width="*" />
                        </grid.columndefinitions>
                        
                        <uielements:gibutton name="btnEdit" xmlns:uielements="#unknown">
                                             Grid.Column="0"
                                             Margin="2"
                                             Height="18"
                                             Width="18"
                                             Command="LocalCommands:Commands.EditBaseRate"
                                             CommandParameter="{Binding}"
                                             VerticalAlignment="Center"
                                             HorizontalAlignment="Stretch"
                                             HorizontalContentAlignment="Stretch"
                                             Style="{DynamicResource IconButtonStyle}">
                            <image source="{DynamicResource Edit}">
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   Height="18"
                                   Width="18"></image>
                        </uielements:gibutton>
                        <uielements:gibutton name="btnDelete" xmlns:uielements="#unknown">
                                             Width="18"
                                             Height="18"
                                             Style="{StaticResource IconButtonStyle}"
                                             HorizontalAlignment="Stretch"
                                             HorizontalContentAlignment="Stretch"
                                             VerticalAlignment="Center"
                                             Grid.Column="1"
                                             Margin="2"
                                             Command="LocalCommands:Commands.DeleteBaseRate"
                                             CommandParameter="{Binding}">
                            <image source="{DynamicResource Delete}">
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   Height="22"
                                   Width="22" />
                        </image></uielements:gibutton>
                        <textblock name="tblChargeCategory">
                                    Margin="2" Width="150"
                                    HorizontalAlignment="Stretch"
                                    Text="{Binding Path=CHARGE_CATEGORY}"
                                    TextTrimming="CharacterEllipsis"
                                    ToolTip="{Binding Text}"
                                    Grid.Column="2" />
                    </textblock></grid>
                        </border>
                </border>
            </datatemplate>



behind the popup window u should create a clr property named as SelectedItem .
XML
private DataRowView _selectedItem;
public DataRowView SelectedItem
{
    get
    {
        return _selectedItem;
    }
    set
    {
        _selectedItem = value;
        OnPropertyChanged("SelectedItem");
    }
}


on edit button click event
call pop window

and create object of pop window and call their property and assign the selected row to that property
 
Share this answer
 
Comments
Member 9454261 25-Sep-12 8:36am    
The data template didn't seem to compile too well - am i right in thinking that just goes in MainWindow.xaml?
vasim sajad 25-Sep-12 8:45am    
datattemplate should be place in xaml file not in xaml.cs file
it cant be compile
Member 9454261 25-Sep-12 12:04pm    
Sorry when i say compile, i mean there were many errors in Visual Studio.
vasim sajad 26-Sep-12 0:07am    
can u post ur code ? or mail me those code (vasim72@gmail.com)
Member 9454261 27-Sep-12 9:32am    
emailed the code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900