Hello!
Can you show the sample how to add the row programmatically ( without ItemsSource property)?
Thank you.
Hi,
The xamWebGrid doesn't have an unbound mode. So there must always be an ItemSource set.
One options, is that you can add an empty ObservableCollection to the xamWebGrid. Then, whenever you add a row to that collection, the xamWebGrid will automatically show that row, as an ObservableCollection implements INotifyCollectionChanged.
I hope this helps,
-SteveZ
Thank you for reply.
I need to have the ability to create a structure of the xamwebgrid programmatically.
I have no linq on the server side, just dataset and datatable, and all data in this (dataset, datatable) is very different (different column names, columns count ). This tables in database creates and changes dynamically by user.
What is the best way in this situation?
Thank you for reply!
1. What should I do with templated columns when I use for binding an anonymouse types?
2. How to bind this anonymouse source to templated columns?
3. What is the best way to create this templated columns when I should bind anonymouse source?
4.How to create in this case subtables? If some columns in this subtables contain templated columns?
Can you show me some lines of code.
I am really disapointed by complexity of it.
So, Anonymous types aren't supported in Silverlight. Which is why i recommend you look into a solution similar to the one in the article i sent.
Also, in this approach, TemplateColumns wouldn't be ideal, as you can't create DataTemplates in the code behind, which requires you to know what types of data you need and names of property in xaml.
So, your best approach would be to use Dynamic types similar to the article, and create columns on the fly, or the use of Autogenerated columns.
I' m not sure what you mean by SubTables, do you mean hiearchy? In which case, hierarchy is just another property in your datasource that is of type IEnumerable.
I know this must be a pain point, however i'd like to make it clear that this is a limitation in the Silverlight framework.
Concerning anonymouse types: I am mistaked :), I consider dynamic types.
1. How to create programmatically column with dropdownlist and button. It is impossible?
2. How to create column with dropdownlist and how to bind it by photos, for example (I am about ValueList dictionary, as in Infragistics WinForms)?
Do you have any examples for this two points?
3.
>>Also, in this approach, TemplateColumns wouldn't be ideal, as you can't create DataTemplates in the >>code behind, which requires you to know what types of data you need and names of property in xaml.
But I can use reflection to read a type, property name and value?
Thank you for your help.
Check out our "Cell Editor Template" sample in the Silverilght LOB samples browser:
http://labs.infragistics.com/silverlight/lobsamples/2009.1/
This sample demonstrates how to put a ComboBox in a Template Column.
In Silverlight, you cannot create a DataTemplate in the code behind. You can create a TemplateColumn in the code behind, however, you'd have to have a predefined DataTemplate in the resources of your xaml, whether its your current page or app.xaml and then resolve the DataTemplate in the codebehind. And since you can't create a DataTemplate in the code behind, it means you'd have to know the names of your properties in advance.
Thank you, Stephen!
Sorry, but I don` t get you.... Is it possible to create row and its column details as HeaderTemplate, ItemTemplate and EditTemplate in the rutime? If yes, just write some lines of code for me, please, because it is impossible without deep knowleges of xamWebGrid.
If it is impossible please write about it.
Sorry for my english...
In my case the number of columns (textcolumns not combobox columns) vary. Is this case posible to render using xamwebgrid. If it is then can you please post the code or attach the entire code for doing the same. In the sample code that you have provided the textblock binds to a specific property. But in my case the property has to be dynamic.
Regards,Sreedhar Buthalapalli
Thank you for help.
1. static resources is best solution for known count of the combobox columns...
But what about if I don`t know how many combobox colums I should create?
2. What about events of the controls within DataTemplate when I create it use XamlReader.Load?
As I see, the xamwebgrid is not able for dynamic structure of the data presetation. The XamWebGrid is ready for static structure, but dynamic is not?
Are you planing the combobox column?
Maby you planing some advance xamwebgrid for REALLY dynamic stucture of the data like Infragistics grid control for win forms?
Thank you
So, the best way to get an ItemSource, that should be calculated dynamically set in a DataTemplate, is to use an IValueConverter.
Where you'd have something like:
<DataTemplate>
<ComboBox ItemSource="{Binding Converter={StaticResource myComboValueConverter}}"/>
</DataTemplate>
Then in your IValueConverter, you'd look at your data object, and return an IEnumerable of the data that should be displayed in the combo.
I`ve found the great problem when I add the combobox into the EditTemplate:
1. I cannot fill the combobox ItemsSource
2. events of this combo is not fire (Loaded event, for example).
3.I cannot get reference to this combo.
I am use the XamlReader to create the DataTemplate (ItemTemplate, EditTemplate, HeaderTemplate) object (as in previouse posts).
Maby possible get reference to this combo in any event of xamwebgrid and fill it by the data and make events?
How to solve this problem? Maby you have any workaround for this? This problem makes me crazy.
I am really need your help. Thank you.
Thank you Stephen!
Last post is really helpful!
Here the sample for other developers, who looks for it.
TemplateColumn CreateDataPickerTemplate(string Header, string bindingProperty, bool EditTemplate, bool HeaderTemplate) { TemplateColumn tcolumn = new TemplateColumn(); tcolumn.HeaderText = Header; tcolumn.Key = bindingProperty; StringBuilder ItemTemplate = new StringBuilder(); ItemTemplate.Append("<DataTemplate"); ItemTemplate.Append(" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" "); ItemTemplate.Append(" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\""); ItemTemplate.Append(" xmlns:igGrid=\"clr-namespace:Infragistics.Silverlight.Controls;assembly=Infragistics.Silverlight.XamWebGrid.v9.1\""); ItemTemplate.Append(" xmlns:controls=\"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls\""); ItemTemplate.Append(" >"); ItemTemplate.Append("<TextBlock Text=\"{Binding "); ItemTemplate.Append(bindingProperty); ItemTemplate.Append(" }\"></TextBlock>"); ItemTemplate.Append(" </DataTemplate>"); tcolumn.ItemTemplate = (DataTemplate)XamlReader.Load(ItemTemplate.ToString()); tcolumn.HeaderTemplate = (DataTemplate)XamlReader.Load(ItemTemplate.ToString()); if (EditTemplate) { StringBuilder EditorTemplate = new StringBuilder(); EditorTemplate.Append("<DataTemplate"); EditorTemplate.Append(" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" "); EditorTemplate.Append(" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\""); EditorTemplate.Append(" xmlns:igGrid=\"clr-namespace:Infragistics.Silverlight.Controls;assembly=Infragistics.Silverlight.XamWebGrid.v9.1\""); EditorTemplate.Append(" xmlns:controls=\"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls\""); EditorTemplate.Append(" >"); EditorTemplate.Append("<controls:DatePicker SelectedDate=\"{Binding "); EditorTemplate.Append(bindingProperty); EditorTemplate.Append(" }\"></controls:DatePicker>"); EditorTemplate.Append(" </DataTemplate>"); tcolumn.EditorTemplate = (DataTemplate)XamlReader.Load(EditorTemplate.ToString()); } return tcolumn; }
this.ZSheet.Columns.Add(CreateDataPickerTemplate("myHeader", "DateTime_field", true, true)); ColumnLayout cl = new ColumnLayout(this.ZSheet); cl.Key = "DateTime_field1"; cl.Columns.Add(CreateDataPickerTemplate("myHeader", "DateTime_field1", true, true)); this.ZSheet.ColumnLayouts.Add(cl);
Onse again thank you!