Hi,
We are using XAMGrid to bind data. But in one column we have multiple comma separated data, these data we want to bind in comboBox. Please let us aware how to bind data in combo box with in XAMGrid.
We are using XAMGrid not XAMDataGrid. Your help would be appreciate.
Thanks
Hello,
The Columns in the XamGrid are not derived from FrameworkElement, which means that they does not have DataContext and when binding the ItemsSource of the ComboBoxColumn you should specify the Source of the binding. You should be able to bind to any collection which implements IEnumerable, so you can split the data and convert it to list of objects. You can than create a StaticResource and bind it to the ItemsSource.
Following this approach I have created a small sample application, you can find it as an attached file.
Thanks for your Reply.
As per your suggestion or demo sample We followed way to bind data in comboBox with in XAMGrid. But here problem is we are following MVVM pattern. We added separate class to bind item source for combo box as per demo sample and this class is bind as resource key. But In our application data is not showing in combo Box. can you please let us aware any other example that using MVVM to bind grid Data and with in this grid we can use combo box.
Thank you for your feedback.
You can use separate class as item source (like in the previous sample) or a property of the ViewModel. In order to do that you can create an instance of the ViewModel through XAML and bind its properties to XamGrid and ComboBoxColumn.You can find an example of this in the attached sample.
Thanks for your wonderful support. We have followed the way as you described and now able to bind data in XAMGrid. But here is main issue is that, combo box data are showing in edit mode and we are not going to allow column to edit in grid. Is there any way to show data in combo Box without allow to edit all data. If its require to show data in edit mode then is there any way in which we can allow to edit only combo box column instead of all row. Please let us aware your help would be a appreciate.
In your scenario you can use EditorDisplayBehavior property and set it to Always.It is applicable in cases such as this one, where the XamGrid is not editable and you want to keep a specific type of column (e.g. ComboBoxColumn, DateColumn, CheckBoxColumn) editable.
You can find it in the modified sample.
In the previous example a collection in the ViewModel was used for a resource for the ComboBoxColumn.
In order the options to be different for each row you have to use another approach. You have to implement a collection for each row. After that you have to use TemplateColumn which in its ItemTemplate you can use Combobox. The data context of the ItemTemplate is the data object that the current row would represent. For example:
<ig:TemplateColumn Key="OptionDataList"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <ComboBox HorizontalContentAlignment="Stretch" DisplayMemberPath="Type" SelectedValuePath="Type" SelectedValue="{Binding OptionToDisplay, Mode=TwoWay}" IsEnabled="True" ItemsSource="{Binding OptionDataList}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> </ig:TemplateColumn>
You can find out more about template columns here
Thanks for your support. I just implemented and working fine except one issue I have. Like if Options value different in grid. But same data showing in comboBox List:
Like: customData.Add(new Data { Name = "Item " + i, Description = "Description " + i, Count = i + 10, Options = "Type One,Type Two" });
customData.Add(new Data { Name = "Item " + i, Description = "Description " + i, Count = i + 10, Options = "Type One" });
But In combo box list: Type One showing in all grid:
Please let us aware. Please let me know if you have any issue. I have attach modified sample.