How to get all the data from DataGrid. And also how to delete a line

It is necessary after changing the line, get either the line number and the changes, or all the lines. In order to change the data from the database (a simple txt file)

datagrid markup

<DataGrid x:Name="LVVid" Grid.Row="1" AutoGenerateColumns="False" CellEditEnding="LVVid_CellEditEnding"> <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <EventSetter Event="MouseDoubleClick" Handler="DataGridRow_MouseDoubleClick"/> </Style> </DataGrid.RowStyle> <DataGrid.Columns> <DataGridTextColumn Header="ФИО" Binding="{Binding FIO}"/> <DataGridTextColumn Header="Курс, направление" Binding="{Binding Kurs}"/> <DataGridTextColumn Header="Место" Binding="{Binding Mesto}"/> <DataGridTextColumn Header="Вид практики" Binding="{Binding Vid}"/> <DataGridTextColumn Header="Начало" Binding="{Binding Nachalo}"/> <DataGridTextColumn Header="Конец" Binding="{Binding Konec}"/> <DataGridTextColumn Header="Руководитель" Binding="{Binding Ruk}"/> </DataGrid.Columns> </DataGrid> 

change processing

 private void LVVid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { string[] str = new string[spisok.Length]; for (int i = 0; i < spisok.Length; i++) { Blank context = spisok[i]; str[i] = spisok[i].FIO + ":" + spisok[i].Kurs + ":" + spisok[i].Mesto + ":" + spisok[i].Vid + ":" + spisok[i].Nachalo + ":" + spisok[i].Konec + ":" + spisok[i].Ruk; } File.Delete("База.txt"); File.AppendAllLines("База.txt", str); } 
  • As the data was added, so take) How do you grid the bin? - Anton Shakalo
  • Use a binding to the collection (via ItemsSource), use the ObservableCollection as the collection, it has a CollectionChanged event. Also, your entities in the collection must implement INOtifyPropertyChanged , then you will be able to receive notifications about their changes. - Andrew NOP
  • at change of DataGrid, the attached data structure changes also? Tobish class with get set fields? - LORD
  • At change DataGrid the data structure in the code does not change. When processing a change, and writing data from a list, the same thing is recorded as before the change - LORD
  • prntscr.com/k3a9k5 here is the screen. I’m changing the specified field, indicating the same field to the output but not from the DataGrid, but from the structure specified in ItemsSource - LORD

0