I have a custom data structure that is pretty much a list of string arrays that I want to display in a (virtual) datagrid in WPF. All the examples of binding I have seen have been to objects with known properties such as a Colors object with a Blue and Red property.
My data is being populated from a SQL query and returns an unknown number of columns.
How can I bind to this type of structure?
(I don't want to use something like ObservableCollection for performance reasons: my data is going to be static so I don't need INotifyPropertyChanged)
See the following question: How to populate a WPF grid based on a 2-dimensional array
If you're only interested in displaying your 2d data then the answer from Jobi Joy will get it done using a Grid
.
If you also want to be able to edit the data then you can use a control I created a while back for this purpose called DataGrid2D
which subclasses DataGrid
To use it, just add a reference to DataGrid2DLibrary.dll, add this namespace
xmlns:dg2d="clr-namespace:DataGrid2DLibrary;assembly=DataGrid2DLibrary"
and then bind it to your List<string[]>
like this
<dg2d:DataGrid2D ItemsSource2D="{Binding ListStringArrayProperty}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With