WPF Application master detail

Markus Freitag 3,786 Reputation points
2020-07-09T06:33:45.65+00:00

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,772 questions
0 comments No comments
{count} votes

11 answers

Sort by: Most helpful
  1. DaisyTian-1203 11,621 Reputation points
    2020-07-09T08:07:22.507+00:00

    I will give you two ways to generate OrderNumbers automatically.
    Method1:

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

    Method2:

     <Window.Resources>
            <ResourceDictionary>
                <local:RowToIndexConverter x:Key="rowToIndexConverter"/>
            </ResourceDictionary>
        </Window.Resources>
    
    <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;
                else
                    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
    2020-07-09T08:17:36.117+00:00

    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?
    Thanks.

    Best regards Markus


  3. Markus Freitag 3,786 Reputation points
    2020-07-09T08:46:16.037+00:00

    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?

    Thanks.


  4. Markus Freitag 3,786 Reputation points
    2020-07-09T09:08:34.383+00:00

    11629--view.png

    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
    2020-07-09T09:14:29.36+00:00

    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
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.