如何动态更新数据网格中组合框列的选择?
我正在尝试将数据表(dt)中的两列显示到数据网格中。并添加另一列,它是一个组合列,以便我可以为每行分配扇区。问题是组合框的选择无法动态更新。当我单击其他内容时,选择消失了。有什么办法可以解决这个问题吗?
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";
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";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有将 ComboBox
Set 中的
SelectedItem
绑定到SelectedItemBinding
或SelectedValueBinding
You're not binding the
SelectedItem
in the ComboBoxSet either
SelectedItemBinding
orSelectedValueBinding
你可以这样尝试......
you Can try like this....