0

I would like to add my DataTable return data to my DataGridTemplateColumn.CellEditingTemplate combobox, But the combo box is empty

My xaml code as follow

 <DataGridTemplateColumn Header="Student">
   <DataGridTemplateColumn.CellEditingTemplate >
      <DataTemplate>
           <ComboBox ItemsSource="{Binding dtStudent}"    DisplayMemberPath="StudentName"/>
      </DataTemplate>
   </DataGridTemplateColumn.CellEditingTemplate>
 </DataGridTemplateColumn>

Back-End

dtStudent = new Function().Sel_Student(); //Function that return student detail

I try to add a Name for the combobox control , but it is not accessible from the back-end .

Is my binding method wrong or do I have other method to achieving what I need

abc cba
  • 2,563
  • 11
  • 29
  • 50

2 Answers2

1

It is not possible to access the control by its name when it is defined in DataTemplate. You can get the ComboBox from its visual tree. Please refer this WPF How to access control from DataTemplate

Community
  • 1
  • 1
Smirti
  • 305
  • 2
  • 12
0

You need to bind to a property and not to a function. So in your back end you should have

public IEnumerable<Student> Students
{
    get
    {
        return Sel_Students();
    }
}

private IEnumerable<Student> Sel_Students()
{
    return { ... your students};
}

public class Student {
}
G Lewis
  • 81
  • 4