Trying to bind to a collection in WPF, I got the following to work:
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 probably but here is 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 what I really need is this in DataGridComboBoxColumn 's. Here are my revisions:
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>
C#:
Stays same.
Problem now is that I get empty combobox columns! Any ideas how I can get this to work?
In the long run I need 2 way binding, where a double click on the firstname column brings up the comobo box which then holds the options of all possible first names in the collection (i.e. George, Jim and Amy).
Grateful any assistance!