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?
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.
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.
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?
I have created a sample project for you with the functionality you want. Basically I set the TempalteColumn’s ItemTempalte, so that the value of the cell could show when not in edit mode. Also I commented a code showing how to get the UserControl’s Resources. Please let me know if this helps you or you need further assistance on this matter.
Hello Hemant,
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking into it and I am wondering if you could send an isolated sample project, where the issue is reproduced, so I can investigate it further for you.
Hello Stefan,
here is my code (Silverlight)
<ig:TemplateColumn.ItemTemplate>
<DataTemplate>
<ig:XamComboEditor>
ItemSource="{Binding Source={StaticResource DataContextProxy}, Path=NameIdList}"
DisplayMemberPath="Name"
IsEditable="True"
AutoComplete="True"
SelectedItem="{Binding NameID, Mode=TwoWay}"
</ig:XamComboEditor>
</DataTemplate>
One problem I am facing is, when i hit backspace key, it gets busted saying 'index was out of range. Must be non -ve'
Please advise.
Hello Vijay,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
Hi Stefan,
Thanks for the sample.
I see that you prepared the sample in WPF, however, I am working in a Silverlight application, but, I guess things will be similar and see if I could extract things of interest from your sample.
I'll let you know once I am done with it.
Thanks again.