Click here to Skip to main content
12,507,343 members (70,822 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# WPF
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 25-Sep-12 0:39am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

i hope your main window contain DataGrid .
create a datatemplate
<datatemplate x:key="DataTemplateBaseChargeSetting" xmlns:x="#unknown">
                <border borderthickness="1">
                          BorderBrush="Transparent"
                          CornerRadius="2"                          
                          HorizontalAlignment="Stretch"
                          Margin="2">


behind the popup window u should create a clr property named as SelectedItem .
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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100