Pergunta

I'm trying to display two columns in a datatable(dt) into a datagrid. And add another column which is a comboxcolumn so that I can assign sectors to each rows. The problem is that the selection of comboboxes cannot be dynamically updated. when I click something else, the selection is gone. Is there any way to fix this?

   dg_display.DataContext = dt.DefaultView;
   dg_display.Columns[0].Header = "Symbol";
   dg_display.Columns[1].Header = "Company name";          
   DataGridComboBoxColumn columnComboBox = new DataGridComboBoxColumn();
   string[] sectorarray = new[]
                                    {
                                       "Consumer Discretionary", "Consumer     Staples", "Energy", "Financial",
                                       "Financials", "Health Care", "Industrials", "Information Technology",
                                       "Materials", "Other", "Technology","Telecommunication Services", "Utilities"
                                   };
        columnComboBox.ItemsSource = sectorarray;
        columnComboBox.IsReadOnly = false;
                    dg_display.Columns.Add(columnComboBox);
        dg_display.Columns[2].Header = "Sector";
Foi útil?

Solução

You're not binding the SelectedItem in the ComboBox

Set either SelectedItemBinding or SelectedValueBinding

Outras dicas

you Can try like this....

 DataGridComboBoxColumn col = new DataGridComboBoxColumn();
        col.Header = "Name";
        col.DisplayMemberPath = "Name"; 
        col.SelectedValueBinding = new Binding("Name");
        col.ItemsSource = simacc;
        col.TextBinding = new Binding("Name");
        col.CanUserSort = false;
        dataGrid1.Columns.Add(col);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top