Click here to Skip to main content
15,881,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please help me figure out how to bind custom class collection to datagrid combobox. My custom class is
C#
class Test: INotifyPropertyChanged
{
    public String Name { get; set; }
    public UserAvailableValue SelectedAvailableValue { get; set; }
    public ObservableCollection<useravailablevalue> AvailableValues { get;  set; }
    public ObservableCollection<string> DefaultValues { get;  set; }
    public String SelectedValue { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

public class UserAvailableValue 
{
    public Object Value { get; set; }
    public Object Label { get; set; }
}

From code behind, i am setting DataGrid Datacontext i.g.
C#
ObservableCollection<test> UIParams = new ObservableCollection<test>();
// code to fill UIParams collection
dgReportparameters.DataContext = UIParams;

//XAML Code
HTML
   <datagrid name="dgReportparameters" itemssource="{Binding}">
               AutoGenerateColumns="False"&gt;
     <datagrid.columns>
     <datagridtextcolumn header="Name" binding="{Binding Name}" />
     <datagridcomboboxcolumn header="Available Values" selecteditembinding="&lt;br" mode="hold" />      "{Binding SelectedAvailableValue, UpdateSourceTrigger=PropertyChanged}" 
       DisplayMemberPath="Label"&gt;
        <datagridcomboboxcolumn.elementstyle>
        &lt;Style TargetType="ComboBox"&gt;
        <setter property="ItemsSource" value="{Binding Path=AvailableValues, &lt;br mode=" hold=" /&gt;         RelativeSource={RelativeSource AncestorType=Window}}" />
         &lt;/Style&gt;
        </datagridcomboboxcolumn.elementstyle>
      
   <datagridtextcolumn header="Default Values" binding="{Binding SelectedValue}" />
   <datagridcheckboxcolumn header="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.
Posted
Updated 5-Jan-15 11:46am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900