The DataTable is populated with the data from a database.
var query = $"SELECT * FROM {databaseTable.Name}";
OracleCommand oracleCommand = new OracleCommand(query, _connection);
OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(oracleCommand);
DataTable data = new DataTable();
oracleDataAdapter.Fill(data);
return data;
I want to populate a DataGrid with the DataTable trough Itemssource. We don't want to specify any objects (classes). We want to fill the Grid with only the informations we get from the DataTable
<control:DataGrid x:Name="gridView1" Margin="5" ItemsSource="{Binding DataTable}" GridLinesVisibility="All" AlternatingRowBackground="DarkBlue">
At the moment I have a ListView that shows me all the Tables that we read out separately from the database
<ListView x:Name="listView" ItemsSource="{Binding DatabaseTables, Mode=TwoWay}" DisplayMemberPath="Name" SelectedItem="{Binding DatabaseTable, Mode=TwoWay}">
and by selecting a table we want all the entries shown in the Grid with the expecting columns from the DataTable
I tried to look around, but couldn't find a solution.
This should work:
MainPageViewModel.cs
MainPage.xaml.cs
MainPage.xaml
NOTE:
I'm using the CommunityToolkit.Mvvm NuGet package for the MVVM design.
UPDATE:
I came up with another solution that might be a bit closer to your requirements. This way you won't need to declare each column in XAML.
DataGridExtensions.cs
MainPageViewModel.cs
and...
MainPage.xaml