开发者

bind datagrid to List<string[]> wpf

开发者 https://www.devze.com 2023-03-28 00:41 出处:网络
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 know

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 t开发者_如何转开发his 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}"/>
  • DataGrid2D Library
  • DataGrid2D Source
0

精彩评论

暂无评论...
验证码 换一张
取 消