Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

how to bind custom class collections to wpf datagrid combobox (multiselected)

$
0
0

Please help me figure out how to bind custom class collection to datagrid combobox. My custom class is

classTest:INotifyPropertyChanged{publicStringName{get;set;}publicUserAvailableValueSelectedAvailableValue{get;set;}publicObservableCollection<UserAvailableValue>AvailableValues{get;set;}publicObservableCollection<String>DefaultValues{get;set;}publicStringSelectedValue{get;set;}publiceventPropertyChangedEventHandlerPropertyChanged;privatevoidRaisePropertyChanged(string propertyName){if(this.PropertyChanged!=null)this.PropertyChanged(this,newPropertyChangedEventArgs(propertyName));}}publicclassUserAvailableValue{publicObjectValue{get;set;}publicObjectLabel{get;set;}}

From code behind, i am setting DataGrid Datacontext i.g.

ObservableCollection<Test>UIParams=newObservableCollection<Test>();// code to fill UIParams collection
   dgReportparameters.DataContext=UIParams;//XAML Code<DataGridName="dgReportparameters"ItemsSource="{Binding}"AutoGenerateColumns="False"><DataGrid.Columns><DataGridTextColumnHeader="Name"Binding="{Binding Name}"/><DataGridComboBoxColumnHeader="Available Values"SelectedItemBinding="{Binding SelectedAvailableValue, UpdateSourceTrigger=PropertyChanged}"DisplayMemberPath="Label"><DataGridComboBoxColumn.ElementStyle><StyleTargetType="ComboBox"><SetterProperty="ItemsSource"Value="{Binding Path=AvailableValues,
         RelativeSource={RelativeSource AncestorType=Window}}"/></Style></DataGridComboBoxColumn.ElementStyle></DataGridComboBoxColumn><DataGridTextColumnHeader="Default Values"Binding="{Binding SelectedValue}"/><DataGridCheckBoxColumnHeader="Nullable"Binding="{Binding IsNullable}"/></DataGrid.Columns></DataGrid>

Except DataGridComboBoxColumn other columns are showing correct values.DataGridComboBoxColumn is showing blank column. UIParams collection has multiple parameters while each parameter has name and Available values and one default value. I want to show paramters in datagrid and let user select one/multiple values from Available column combobox. Each parameter has its own set of available values. Most of the example i found have Common collection in dropdown but in my case each row of datagrid has different available values.

Please help me to have combobox in datagrid.

Thanks in advance.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>