WPF Application master detail

Markus Freitag 3,786 Reputation points

Hello together,

I want to add a order number, then add a material number with quantity.

Master, Detail with C#

OrderNumber = ………

Fill the list OrderNumbers

On right site I need a MaterialList

Input: Material = …….. Quantity = ……

     Add, Edit, Delete Button

Fille the list with MaterialNumbers and Quantity

Save it as XML.

Should be possible to reload it.

I'm looking for a good sample code.

Thanks in advance for your help!

Regards Markus

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,709 questions
0 comments No comments
{count} votes

11 answers

Sort by: Most helpful
  1. DaisyTian-1203 11,621 Reputation points

    I will give you two ways to generate OrderNumbers automatically.

    private void MyDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
                e.Row.Header = (e.Row.GetIndex() + 1).ToString();


                <local:RowToIndexConverter x:Key="rowToIndexConverter"/>
    <DataGridTextColumn Header="OrderNumbers " Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource rowToIndexConverter}}" />

    The converter is:

    public class RowToIndexConverter : IValueConverter
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                DataGridRow row = value as DataGridRow;
                if (row != null)
                    return row.GetIndex() + 1;
                    return -1;
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                throw new NotImplementedException();
    1 person found this answer helpful.
    0 comments No comments

  2. Markus Freitag 3,786 Reputation points

    Thanks for the quick response.
    I have a TextBox enter the new number Like 20200709-Cust7654.

    The add button should fill the listbox.

    For material, I need two columns, like grid.
    Can you post more details?

    Best regards Markus

  3. Markus Freitag 3,786 Reputation points

    Thanks, looks good, but not perfect.

    I need a own list for orders.
    A detail list for material and quantity and comment.

    Primary Key. Foreign Key.
    Save as XML.

    If I edit, _showCellseditingTemplate null exception.

    Can you help again, pleased?


  4. Markus Freitag 3,786 Reputation points


    Yes I need MVVM.

    I enter the order number. For each order numbers I can use different materials.
    I need a textbox for material and for quantity, and yes for comment, why not.
    A ADD button for fill the list, a button to delete whe whole list and for each row a button to delete a special item as you do it.

    Thanks for help.

    0 comments No comments

  5. Markus Freitag 3,786 Reputation points

    A SAVE button to save it as XML file.
    A LOAD button to reload it inside the view.

    The name of the file is OrderNumber.XML

    If a order is selected, the SAVE button is enable and I can exactly save this order with the right material list.

    Relation is Order 1:n Material

    Hope now clear what I need.

    MVVM I need, yes. Is not all clear for how it is work. I need a good model.

            public event PropertyChangedEventHandler PropertyChanged;
            protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
            ICommand handler