Trying to bind to a collection in WPF, I got the following:
XAML:
<toolkit:DataGrid Name="dgPeoples"/>
CS:
namespace DataGrid { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 { private readonly ObservableCollection<Person> personList = new ObservableCollection<Person>(); public Window1() { InitializeComponent(); personList.Add(new Person("George", "Jung")); personList.Add(new Person("Jim", "Jefferson")); personList.Add(new Person("Amy", "Smith")); dgPeoples.ItemsSource = personList; } } }
unnessecary, perhaps, but here is the Person class:
namespace DataGrid { public class Person { public string fName { get; set; } public string lName { get; set; } public Person(string firstName, string lastName) { fName = firstName; lName = lastName; } } }
But I really need this in a DataGridComboBoxColumn . Here are my changes:
XAML:
<toolkit:DataGrid Name="dgPeoples" Grid.Row="0" AutoGenerateColumns="False"> <toolkit:DataGrid.Columns> <toolkit:DataGridComboBoxColumn Width="5*"/> <toolkit:DataGridComboBoxColumn Width="5*"/> </toolkit:DataGrid.Columns> </toolkit:DataGrid>
FROM#:
Remains the same.
The problem now is that I get empty columns with a list! Any ideas how I can make this work?
Ultimately, I need to bind 2 paths, where double-clicking on the firstname column calls the comobo field, which then stores options for all possible first names in the collection (for example, George, Jim and Amy).
Thanks for the help!
baron source share