ComboBox-Inhalt an DataGrid senden

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • ComboBox-Inhalt an DataGrid senden

    Hey Leute.
    Ich bin heute dabei, einen sog. Noten-Organizer zu programmieren. Ich möchte allerdings, wenn ich einen bestimmten Button drücke, dass die Inhalte von mehreren ComboBoxen, einem DatePicker und einem RadioButton in den DataGrid übertragen werden.
    Hier mein XAML:

    Source Code

    1. <Window x:Class="Noten_Organizer_Ver._1._1.MainWindow"
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    6. xmlns:local="clr-namespace:Noten_Organizer_Ver._1._1"
    7. mc:Ignorable="d"
    8. Title="MainWindow" Height="630" Width="940" ResizeMode="CanMinimize" Background="#FFBDB7B7" WindowStartupLocation="CenterScreen">
    9. <Grid>
    10. <Grid.ColumnDefinitions>
    11. <ColumnDefinition Width="5"/>
    12. <ColumnDefinition Width="35"/>
    13. <ColumnDefinition Width="138"/>
    14. <ColumnDefinition Width="75"/>
    15. <ColumnDefinition Width="5"/>
    16. <ColumnDefinition Width="75"/>
    17. <ColumnDefinition Width="5"/>
    18. <ColumnDefinition Width="150"/>
    19. <ColumnDefinition Width="5"/>
    20. <ColumnDefinition Width="150"/>
    21. <ColumnDefinition Width="5"/>
    22. <ColumnDefinition Width="100"/>
    23. <ColumnDefinition Width="5"/>
    24. <ColumnDefinition Width="100"/>
    25. <ColumnDefinition Width="64"/>
    26. <ColumnDefinition Width="6"/>
    27. </Grid.ColumnDefinitions>
    28. <Grid.RowDefinitions>
    29. <RowDefinition Height="20"/>
    30. <RowDefinition Height="30"/>
    31. <RowDefinition Height="25"/>
    32. <RowDefinition Height="25"/>
    33. <RowDefinition Height="396"/>
    34. <RowDefinition Height="40"/>
    35. <RowDefinition Height="25"/>
    36. <RowDefinition Height="5"/>
    37. </Grid.RowDefinitions>
    38. <Button Name="Speichern" Content="Speichern" Grid.Column="13" Grid.Row="6" BorderBrush="Black" Click="Speichern_Click"/>
    39. <Button Name="Beenden" Content="Beenden" Grid.Column="11" Grid.Row="6" BorderBrush="Black" Click="MenuItem_Click_1"/>
    40. <Label Name="Fach_lbl" Content="Fach:" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="1" FontWeight="Bold" FontSize="18" FontStyle="Italic"/>
    41. <ComboBox Name="Fach" BorderBrush="Black" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="2" VerticalContentAlignment="Center">
    42. <ComboBoxItem Content="Deutsch"></ComboBoxItem>
    43. <ComboBoxItem Content="Englisch"></ComboBoxItem>
    44. <ComboBoxItem Content="IT-Systeme"></ComboBoxItem>
    45. <ComboBoxItem Content="Vernetzte Systeme"></ComboBoxItem>
    46. <ComboBoxItem Content="Anwendungsprogrammierung"></ComboBoxItem>
    47. <ComboBoxItem Content="Religion"></ComboBoxItem>
    48. <ComboBoxItem Content="Sozialkunde"></ComboBoxItem>
    49. <ComboBoxItem Content="BWP"></ComboBoxItem>
    50. </ComboBox>
    51. <Label Name="Note_lbl" Content="Note:" Grid.Column="5" Grid.Row="1" FontWeight="Bold" FontSize="18" FontStyle="Italic"/>
    52. <ComboBox Name="Note" BorderBrush="Black" Grid.Column="5" Grid.Row="2" VerticalContentAlignment="Center">
    53. <ComboBoxItem Content="1"></ComboBoxItem>
    54. <ComboBoxItem Content="2"></ComboBoxItem>
    55. <ComboBoxItem Content="3"></ComboBoxItem>
    56. <ComboBoxItem Content="4"></ComboBoxItem>
    57. <ComboBoxItem Content="5"></ComboBoxItem>
    58. <ComboBoxItem Content="6"></ComboBoxItem>
    59. </ComboBox>
    60. <Label Name="Lehrer_lbl" Content="Lehrer:" FontSize="18" FontStyle="Italic" FontWeight="Bold" Grid.Column="7" Grid.Row="1"/>
    61. <ComboBox Name="Lehrer" BorderBrush="Black" Grid.Column="7" Grid.Row="2">
    62. <ComboBoxItem Content="Thiel"></ComboBoxItem>
    63. <ComboBoxItem Content="Yilmaz"></ComboBoxItem>
    64. <ComboBoxItem Content="Jaud"></ComboBoxItem>
    65. <ComboBoxItem Content="Bettio"></ComboBoxItem>
    66. <ComboBoxItem Content="Eichert"></ComboBoxItem>
    67. </ComboBox>
    68. <DatePicker Name="Datum" Grid.Column="9" Grid.Row="2" VerticalContentAlignment="Center" HorizontalContentAlignment="Stretch" Background="#FFBDB7B7" BorderBrush="Black"/>
    69. <Button Name="Note_eintragen" Content="Note eintragen" FontWeight="Medium" TextOptions.TextFormattingMode="Display" Grid.Column="13" Grid.ColumnSpan="2" Grid.Row="2" Click="Note_eintragen_Click"/>
    70. <RadioButton Name="Ex" Content="Ex" Grid.Column="11" Grid.Row="1" VerticalAlignment="Center" Margin="0,9,0,8" Height="14"/>
    71. <RadioButton Name="Schulaufgabe" Content="Schulaufgabe" Grid.Column="11" Grid.Row="2" VerticalAlignment="Top" Margin="0,6,0,0" Height="16"/>
    72. <Label Name="schnitt" Content="Durchschnitt insgesamt:" Grid.Column="2" Grid.Row="6" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="11" Height="26" Width="126"/>
    73. <Label Name="notenschnitt" Content="Test" Grid.Column="3" Grid.Row="6" VerticalAlignment="Top" FontSize="11"/>
    74. <DataGrid Name="Liste" Grid.Column="1" Grid.ColumnSpan="14" Grid.Row="4" CanUserResizeRows="False" CanUserResizeColumns="False" RowDetailsVisibilityMode="Visible" BorderBrush="Black" Background="#FFE8E8E8" AlternatingRowBackground="Gray" AlternationCount="2">
    75. <DataGrid.Columns>
    76. <DataGridTemplateColumn Header="Fach" Width="100"/>
    77. <DataGridTemplateColumn Width="50" Header="Note"/>
    78. <DataGridTemplateColumn Width="100" Header="Lehrer"/>
    79. <DataGridTemplateColumn Width="150" Header="Datum"/>
    80. <DataGridTemplateColumn Width="100" Header="Typ"/>
    81. </DataGrid.Columns>
    82. </DataGrid>
    83. <Menu Name="Menü" Background="#FF8F8F8F" Grid.Column="0" Grid.ColumnSpan="2">
    84. <MenuItem Header="Datei" Height="20" Width="36">
    85. <MenuItem Header="Fach hinzufügen" Command="Close" Click="MenuItem_Click_2"/>
    86. <MenuItem Header="Lehrer hinzufügen" Command="Close" Click="MenuItem_Click_3"/>
    87. <MenuItem Header="Info" Click="MenuItem_Click"/>
    88. <Separator />
    89. <MenuItem Header="Beenden" Click="MenuItem_Click_1"/>
    90. </MenuItem>
    91. </Menu>
    92. </Grid>
    93. </Window>
    Display All





    Hier mein C#:

    C Source Code

    1. using System;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using System.Linq;
    5. using System.Text;
    6. using System.Threading.Tasks;
    7. using System.Windows;
    8. using System.Windows.Controls;
    9. using System.Windows.Data;
    10. using System.Windows.Documents;
    11. using System.Windows.Input;
    12. using System.Windows.Media;
    13. using System.Windows.Media.Imaging;
    14. using System.Windows.Navigation;
    15. using System.Windows.Shapes;
    16. namespace Noten_Organizer
    17. {
    18. /// <summary>
    19. /// Interaktionslogik für MainWindow.xaml
    20. /// </summary>
    21. public partial class MainWindow : Window
    22. {
    23. public MainWindow()
    24. {
    25. InitializeComponent();
    26. }
    27. //Infofenster in "Datei" wird geöffnet
    28. private void MenuItem_Click(object sender, RoutedEventArgs e)
    29. {
    30. Window win2 = new Info();
    31. win2.Show();
    32. }
    33. //Mainfenster in "Datei -> Beenden" wird geschlossen
    34. private void MenuItem_Click_1(object sender, RoutedEventArgs e)
    35. {
    36. if (MessageBox.Show("Wollen Sie das Programm wirklich beenden? \n\nVergessen Sie nicht zu Speichern!!", "Beenden?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
    37. {
    38. Close();
    39. }
    40. }
    41. //Fach hinzufügen in "Datei" wird geöffnet
    42. private void MenuItem_Click_2(object sender, RoutedEventArgs e)
    43. {
    44. Window win2 = new Fach_hinzufügen();
    45. win2.Show();
    46. }
    47. //Lehrer hinzufügen in "Datei" wird geöffnet
    48. private void MenuItem_Click_3(object sender, RoutedEventArgs e)
    49. {
    50. Window win2 = new Lehrer_hinzufügen();
    51. win2.Show();
    52. }
    53. //Button "Beenden" im MainWindow
    54. private void Beenden_Click(object sender, RoutedEventArgs e)
    55. {
    56. if (MessageBox.Show("Wollen Sie das Programm wirklich beenden? \n\nVergessen Sie nicht zu Speichern!!", "Beenden?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
    57. {
    58. Close();
    59. }
    60. }
    61. //Button "Note eintragen" im MainWindow
    62. private void Note_eintragen_Click(object sender, RoutedEventArgs e)
    63. {
    64. }
    65. private void Speichern_Click(object sender, RoutedEventArgs e)
    66. {
    67. }
    68. }
    69. }
    Display All




    Der Button "Note eintragen" soll die von mir gewünschte Funktion auslösen.
    Danke jetzt schon

    Euer Kirk

    The post was edited 3 times, last by Kirk1701A ().