none
WPF 4 DataGrid RowEditEnding

    Question

  • How Can Get user input value?

    private void dgData_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
            {
                if (e.EditAction == DataGridEditAction.Commit)
                {

                      Employee employee = e.Row.DataContext as Employee;

                      //in wpf toolkit ,I Can get the new value.

                      //but in WPF 4 ,I only get old input value.              

                      Console.Writeline(employee.Name);

                }

    Sunday, May 02, 2010 3:57 AM

Answers

  • Hi 到此一游,

    The DataGrid control in WPF 4 is a little different with the DataGrid in WpfToolkit. By default, it updates the data after the selecting row changed, so we cannot get the new value in the RowEditEnding event .

    We can solve this problem by setting the UpdateSourceTrigger of the binding, For example, we can set the  UpdateSourceTrigger as PropertyChanged so that wen can get the new value in the RowEditEnding event.

    Something likes the follows:

    <DataGrid AutoGenerateColumns="False" Name="datagrid" ItemsSource="{Binding}" RowEditEnding="datagrid_RowEditEnding">

        <DataGrid.Columns>

            <DataGridTextColumn Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged}" Header="Name"></DataGridTextColumn>

            <DataGridTextColumn Binding="{Binding Age}" Header="Age"></DataGridTextColumn>

        </DataGrid.Columns>

    </DataGrid>


    Hope this helps.

    Best regards,
    Linda Liu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by 到此一游 Saturday, May 08, 2010 9:18 AM
    Friday, May 07, 2010 5:44 AM

All replies

  • That is most curious. If you use CellEditEnding you can access the EditElement and its value.
    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Tuesday, May 04, 2010 1:31 PM
  • Hi All,

    I have the same problem when porting the WPF application to WPF 4. I used the following code inside the CellEditEnding event handler:

     

    TextBox textBox = e.EditingElement as TextBox;

    if

     

     

    (textBox != null)

    {

        String newValue = textBox.Text;

        ....

    }

     

     

    Tuesday, May 04, 2010 2:29 PM
  • Hi 到此一游,

    The DataGrid control in WPF 4 is a little different with the DataGrid in WpfToolkit. By default, it updates the data after the selecting row changed, so we cannot get the new value in the RowEditEnding event .

    We can solve this problem by setting the UpdateSourceTrigger of the binding, For example, we can set the  UpdateSourceTrigger as PropertyChanged so that wen can get the new value in the RowEditEnding event.

    Something likes the follows:

    <DataGrid AutoGenerateColumns="False" Name="datagrid" ItemsSource="{Binding}" RowEditEnding="datagrid_RowEditEnding">

        <DataGrid.Columns>

            <DataGridTextColumn Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged}" Header="Name"></DataGridTextColumn>

            <DataGridTextColumn Binding="{Binding Age}" Header="Age"></DataGridTextColumn>

        </DataGrid.Columns>

    </DataGrid>


    Hope this helps.

    Best regards,
    Linda Liu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by 到此一游 Saturday, May 08, 2010 9:18 AM
    Friday, May 07, 2010 5:44 AM
  • Thank you.

     

    Saturday, May 08, 2010 9:19 AM
  • Dear Linda!

     

    I am binding list of entities with WPF 4 DataGrid, but still facing problems in insertion & updation. Can you please help me with a  sample project.

     

    Best Regards,

    Muhammad K. Shehzad

    Monday, February 28, 2011 1:46 PM