6

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)

2
  • Are you using WPF3 or WPF4? Basically which type of Grid? Commented Aug 12, 2011 at 22:44
  • I'm using WPF4 - it's the DataGrid that was formerly part of the WPF Toolkit Commented Aug 12, 2011 at 23:01

1 Answer 1

2

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}"/>
Sign up to request clarification or add additional context in comments.

2 Comments

The download URL is broken. Google currently returns this URL instead: mediafire.com/?9xrq5obde90b67o
@Erij J: I just tried it and it seems to be working fine now. Are you still having trouble with the link? Maybe a temporary problem with mediafire. I'll move it to dropbox instead when I get the chance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.