Bind datagrid to list <string []> wpf

I have a custom data structure that pretty much represents a list of string arrays that I want to display in a (virtual) datagrid in WPF. All the binding examples that I saw were related to objects with known properties, such as a Colors object with a blue and red property.

My data is populated from an SQL query and return 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 will be static, so I don't need INotifyPropertyChanged)

+6
source share
1 answer

See the next question: How to populate a WPF grid based on a two-dimensional array

If you are only interested in displaying your 2d data, then the answer from Jobi Joy will be done using the Grid .

If you also want to be able to edit data, you can use the control that I created for this purpose, called DataGrid2D , which subclasses of DataGrid

To use it, just add a link to DataGrid2DLibrary.dll, add this namespace

 xmlns:dg2d="clr-namespace:DataGrid2DLibrary;assembly=DataGrid2DLibrary" 

and then bind it to List<string[]> as follows

 <dg2d:DataGrid2D ItemsSource2D="{Binding ListStringArrayProperty}"/> 
+2
source

Source: https://habr.com/ru/post/894949/


All Articles