Hi,
I am trying to add XamComboEditor to a XamGrid column.
I want to set the ItemSource of this XamComboEditor via code, it is dynamic and it'll keep changing means I'll change the itemsource to other collection as well.
Want to allow user to either select from existing, or let Enter new value in the cell.
I used below code to get the xamcomboeditor in my grid:
<ig:TemplateColumn Key="Band" IsReadOnly="False"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock x:Name="DisplayName" Text="{Binding}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <ig:XamComboEditor IsEditable="True" CustomValueEnteredAction="Add" ItemsSource="{Binding}" SelectedItem="{Binding}"> <ig:XamComboEditor.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding}"/> </DataTemplate> </ig:XamComboEditor.ItemTemplate> </ig:XamComboEditor> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn>
I am not getting as how to set the itemsource to this column via code (at runtime)
Any suggestions/directions?
i some how got it PARTIAL working - with below changes:
1. earlier my datastore (collection of objects) was part of MainPage, i created another class (MyModel) having this datastore as property.
2. Have to set "DataContext = new MyModel();"
3. XAML:
<UserControl.Resources> <local:MyModel x:Key="cbs" /> </UserControl.Resources>
4. XAML:
<ig:TemplateColumn Key="KeyInGridDataSource" IsReadOnly="False" > <ig:TemplateColumn.EditorTemplate> <DataTemplate> <ig:XamComboEditor x:Name="gridXamComboEditor" IsEditable="True" CustomValueEnteredAction="Add" ItemsSource="{Binding Source={StaticResource cbs}, Path=cbBandSource, Mode=TwoWay}" SelectedItem="{Binding ID, Mode=TwoWay}" AutoComplete="True" DropDownOpening="gridXamComboEditor_DropDownOpening" ItemAdded="gridXamComboEditor_ItemAdded" SelectionChanged="gridXamComboEditor_SelectionChanged" > </ig:XamComboEditor> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn>
Now: to my surprise:
When I double click the cell, I get the nice comboeditor, populated with dataStore items. Good.
When I select one of the item, and clicks anywhere to exit the edit, the selected value does not appear in grid.
I had to write a handler (gridXamComboEditor_SelectionChanged) to set the value in underlaying object so that it appear in grid.
If the cell already has some value, and cell is double clicked for editing, value is not displayed as selected comboeditor(?)
If the cell already has some value (which is NOT in dataStore) it is not displayed in the comboeditor.
NOW: Important thing is: I want to access the MyModel dataStore and change it to different set of objects based on some actions.
How can I access the UserControl resource?
hi.
Thanks for the link.
1. i created a List<ofmyclass> cmbStore as a property of MainPage (this list need to be set as itemssource to xamcomboeditor in the grid column)
2. declared xmlns:local,
xmlns:local="clr-namespace:NameSpaceOfMainPage"
3. declared <UserControl.Resources> as
<UserControl.Resources> <local:MainPage x:Key="cbs" /> </UserControl.Resources>
3. set the templatecolumn in the xamgrid as :
<ig:TemplateColumn Key="KeyInGridDataSource" IsReadOnly="False"> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <ig:XamComboEditor x:Name="gridXamComboEditor" IsEditable="True" CustomValueEnteredAction="Add" ItemsSource="{Binding Source={StaticResource cbs}, Path=cmbStore}" SelectedItem="{Binding ID}"> <ig:XamComboEditor.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding ID}"/> </DataTemplate> </ig:XamComboEditor.ItemTemplate> </ig:XamComboEditor> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn>
However, it fails to load and throwing StackOverflowExcpetion on InitializeComponent() call in MainPage constructor! :(
Couldn't think of what am i missing here.
Hello,
Thank you for your post. I have been looking into it and I can suggest you see this forum thread:
https://ko.infragistics.com/community/forums/f/retired-products-and-controls/72619/xamgrid-combobox-column-binding/367482#367482
where a similar issue is discussed. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.