0

I Have a data grid of objects (CopyObject) , each object contains list of objects (PGroupGridObject) that i want to display inside combo box.

My View Model :

private ObservableCollection<CopyObject> foldersToCopy;
        public ObservableCollection<CopyObject> FoldersToCopy 
{ get => foldersToCopy; set { foldersToCopy = value; OnPropertyChanged("FoldersToCopy"); } }

CopyObject class :

 public class CopyObject 
    {
        public ObservableCollection<PGroupGridObject> pGroups;
        public CopyObject(string s , ObservableCollection<PGroupGridObject> pGroups)
        {
            Name = s;
            IsFolder = (File.GetAttributes(Name) & FileAttributes.Directory) == FileAttributes.Directory;
            this.pGroups = pGroups;
        }
        public string Name { get; set; }
    }

PGroupGridObject class :

public class PGroupGridObject : ViewModelBase
    {

        public PGroupGridObject(object o)
        {
            Object = (DeployTool.Domain.Model.PGroup)o;
            PGroupName = Object.Name;
            ProductName = Object.Project_Product.Name;
        }
        private bool isChecked { get; set; }
        private string pGroupName;
        public string PGroupName
        {
            get { return pGroupName; }
            set
            {
                pGroupName = value;
                OnPropertyChanged("PGroupName");
            }
        }

        public bool IsChecked
        {
            get { return isChecked; }
            set
            {
                isChecked = value;
                OnPropertyChanged("IsChecked");
            }
        }
    }

my xaml :

        <DataGrid ItemsSource="{Binding FoldersToCopy}" Grid.Row="7" Grid.Column="1" SelectionUnit="FullRow" RowHeaderWidth="0" SelectedItem="{Binding CopyObjectSelected}"
                  Style="{StaticResource DataGridStyle}" d:ItemsSource="{d:SampleData ItemCount=2}" AutoGenerateColumns="False"
                  MinHeight="60" MaxHeight="180" Margin="0,10,0,10"
                  Foreground="White" Background="#292929" FontSize="16" BorderThickness="0" HorizontalAlignment="Right" MaxWidth="800" MinWidth="600" >
                <DataGrid.Columns>
                    <DataGridTextColumn Header="File Path" Binding="{Binding Name}" CanUserResize="True" MinWidth="520"/>
                    <DataGridComboBoxColumn Header="PGroups" 
                    ItemsSource="{Binding pGroups, UpdateSourceTrigger=PropertyChanged}"
                    DisplayMemberPath="{Binding PGroupName}"
                    />

                </DataGrid.Columns>
            </DataGrid>

All the examples I found show Bind from the View Model and not from the object in the grid. the goal eventually is to display check box inside every group in combo box.

I would appreciate help.

Michael
  • 11
  • 3

1 Answers1

1

pGroups must be a public property for you to be able to bind to it:

public ObservableCollection<PGroupGridObject> pGroups { get; }

Also, the DisplayMemberPath should be set to a string that matches the name of a property of a PGroupGridObject:

DisplayMemberPath="PGroupName"
mm8
  • 163,881
  • 10
  • 57
  • 88