I have a grid (Silverlight3 built-in) where I build all the columns dynamically by setting the itemssource to a dictionary object. I bind all columns to the same property and then use converters with converter parameter to fetch the correct value from the dictionary.
I want to use the same solution but just with your grid (XamWebGrid). I'm not very familiar yet with your grid so I may be doing things completely the wrong way. I used the Key property of the TextColumn to "bind" the column to a certain property. This works fine first time but on second column I get an error that I must have unique Key names.
Is it possible for me to bind all columns to the same property? I found the ValueConverter and ValueConverterParameter properties of the TextColumn which I can use to achieve the rest of my requirements.
Hi,
Yes, but you'd need to use the TemplateColumn, instead of the TextColumn. In which case, you would use the ItemTemplate property, and provide a DataTemplate, with your Binding and Converter:<DataTemplate> <TextBlock Text={Binding Prop, Converter={StaticResource MyConverter}, ConverterParameter=Test}/> </DataTemplate>
Then, for each column, you would provide a unique key, as the key on a TemplateColumn doesn't require a link between the underlying data.
-SteveZ
I need to do all of this on code as the columns are dynamic on this case. I think I saw a discussion somewhere stating that I can't do the template on code behind and I would have to use XAML for that which is a showstopper for me.
Hi anttisimonen,I have created a sample project that uses xamwebgrid to display the columns dynamically. I am using the dictionary object (I saw this methodology on the internet)I customized it to xamwebgrid. The attachment contains the files. My data is in the form of xml.You can modify the xml to load as many no. of columns you require.
Regards,Sreedhar B
I was just testing a similar method by manually building the DataTemplate string and then use XamlReader to load it up to the column. However, I don't like this solution very much, it's a dirty workaround :). If I could just hook up the binding in code-behind, like I can do with SL default datagrid, I would be very happy.
Check out the following post which talks about the various ways to achieve this functionality.
http://community.infragistics.com/forums/t/32185.aspx
Also, here is another thread that talks about doing this with a dictionary of items:
http://community.infragistics.com/forums/t/32460.aspx
Thanks for this solution. I got it working and I like it a lot more than writing manually the datatemplate string.