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, 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...
I actually thought about it a bit more, and i suppose you could use a XamlReader to generate a DataTemplate at runtime.
A colleague of mine actually pointed out an Article that shows this. It's using the MS DataGrid however, it translates the same way.
http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx
Hope this helps.
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!
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.
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.
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