B
bigboi27
Guest
Hi, I've been trying to get a selected item from a combobox in a datagrid cell.
I have an automatically generated datagrid depending on a list of items. This is my code:
ObservableCollection<Eclass> obsCollection = new ObservableCollection<Eclass>(this.e);
DataGridE.DataContext = obsCollection;
DataGridE.Columns[0].IsReadOnly = true;
DataGridE.Columns[1].Header = "Esp (m)";
DataGridComboBoxColumn descrip = new DataGridComboBoxColumn();
descrip.ItemsSource = new List<string> { "G", "C"};
descrip.Header = "Description";
descrip.TextBinding = new Binding("Description");
DataGridE.Columns[2] = descrip;
//that is the code to generate the grid
//this is the code to get some of the items
for (int i = 0; i < this.e.Count; i++){
TextBlock esp = DataGridE.Columns[1].GetCellContent(DataGridE.Items) as TextBlock;
It works great for esp since I can then convert that to a value or a String. But for the combobox column which is the DataGridE.Columns[2] I have no idea how to get the selected item or index, preferably item.
I have tried doing something similar with getcellcontent but it just doesn't work.
Any help is appreciated.
Continue reading...
I have an automatically generated datagrid depending on a list of items. This is my code:
ObservableCollection<Eclass> obsCollection = new ObservableCollection<Eclass>(this.e);
DataGridE.DataContext = obsCollection;
DataGridE.Columns[0].IsReadOnly = true;
DataGridE.Columns[1].Header = "Esp (m)";
DataGridComboBoxColumn descrip = new DataGridComboBoxColumn();
descrip.ItemsSource = new List<string> { "G", "C"};
descrip.Header = "Description";
descrip.TextBinding = new Binding("Description");
DataGridE.Columns[2] = descrip;
//that is the code to generate the grid
//this is the code to get some of the items
for (int i = 0; i < this.e.Count; i++){
TextBlock esp = DataGridE.Columns[1].GetCellContent(DataGridE.Items) as TextBlock;
It works great for esp since I can then convert that to a value or a String. But for the combobox column which is the DataGridE.Columns[2] I have no idea how to get the selected item or index, preferably item.
I have tried doing something similar with getcellcontent but it just doesn't work.
Any help is appreciated.
Continue reading...