There was a question how is it possible to set a binding (binding) in a dataGrid to more than one entity (this is a class for displaying a table from a database)? The use of 3 dataGrid elements or snapping to cells by index (for example, directly specifying columns [0]) seems to be very doubtful, so I would like to understand and use the binding mechanisms.


I get the question:

How to bind to one dataGrid more than one data source using a binding, for example, with one source, you need a binding and data mapping structure presented below:

<DataGrid x:Name="dataGrid_1"> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding dateAuthorizLic, StringFormat=\{0:dd.MM.yyyy HH:mm\}}" Header="Дата выдачи"/> <DataGridTextColumn Binding="{Binding nameProgram}" Header="Программа"/> <DataGridTextColumn Binding="{Binding nameCustomer}" Header="Заказчик"/> </DataGrid.Columns> </DataGrid> 

To display data from another source, you need the following binding:

  <DataGrid x:Name="dataGrid_2"> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding nameKor}" Header="Корректор"/> <DataGridTextColumn Binding="{Binding name}" Header="Наименование"/> <DataGridTextColumn Binding="{Binding count}" Header="Количество"/> </DataGrid.Columns> </DataGrid> 
  • why not 3 different view instances? field types are different, data is different, for what you want to make one universal grid? - Bald
  • Yes, one is universal, since only one is used in active mode. 3 grids are now implemented, and it seems to me that this is not the best solution, I would like to consult on this matter. - Spiffo
  • at the moment you have it all 2 different grids (they are similar only to the number of columns), as it seems to me, there should be all the same 2 grids here. - Bald
  • @Bald I gave as an example) - Spiffo
  • Autogenerate columns enable - Andrew NOP

0