I have a list of string array as input. The array dimension are static for all the list but I can’t know the array size until the list is retrieved. I need to bind the list in a datagrid in Silverlight.
I tried to create columns at runtime, binding each column to a particular array position but cannot find a way.
Have you any idea how to do it?
I could eventually ‘convert’ my list of array in anything else that could be binded in a datagrid?
The idea is to have a sort of 2d Matrix showed inside the datagrid in Silverlight (I think that the problem is similar).
List
column_1 column_2 column_3 .. column_m string[1,1] string[1,2] string[1,3] .. string[1,m] string[2,1] string[2,2] string[2,3] .. string[2,m] string[3,1] string[3,2] string[3,3] .. string[3,m] .... string[n,1] string[n,2] string[n,3] .. string[n,m]
n is list lenght, m is list column max number.
Any idea is appreciated
Unfortunately that’s not gonna be easy.
Do you have any valid constraints, like the maximum number of columns that is allowed or anything like that? If you do (let’s say you have N column maximum), you might be able to do something by
That’s kind of ugly, but it would work.
If you do not have to rely on the DataGrid, there is a possibility using a UniformGrid. A UniformGrid is a panel that layouts its children in a regular grid (every item has the same width, every item has the same height). You can indicate the number of columns at runtime, and the panel will fit children one after the other up to the number of columns and then continue on another line. You could bind an ItemsControl to your array, indicating it should use a UniformGrid as its layout panel and indicating a suitable ItemTemplate to render each string.
The second option is much easier, but you will not have the capabilities of the DataGrid like sorting, moving columns, row selection, edition events per row etc.