【发布时间】:2019-02-18 02:13:41
【问题描述】:
我的会计科目表中有一个列表视图:
public class ChartOfAccounts
{
public int AccountCode { get; set; }
public string AccountTitle { get; set; }
public string Description { get; set; }
public string SubCategory { get; set; }
public string Category { get; set; }
public bool Active { get; set; }
}
通过此列表视图,我想填充其他控件,例如:
private void MainRadDataGrid_SelectionChanged(object sender, Telerik.UI.Xaml.Controls.Grid.DataGridSelectionChangedEventArgs e)
{
RadDataGrid rdg = (RadDataGrid)sender;
var SelectedCOA = (ChartOfAccounts)rdg.SelectedItem;
if (rdg !=null && rdg.SelectedItems.Count > 0) {
AccountCodeTextBox.Text = SelectedCOA.AccountCode.ToString();
AccountTitleTextBox.Text = SelectedCOA.AccountTitle;
DescriptionTextBox.Text = SelectedCOA.Description;
CategoryComboBox.SelectedItem = SelectedCOA.Category;
SubCategoryComboBox.SelectedItem = SelectedCOA.SubCategory;
}
}
问题是,我无法将Category 和SubCategory 组合框设置为相关的Category 和SubCategory。 ComboBox 仅显示 Category 和 Sub Category 单词,而不是实际选中的项目。
谁能解释为什么这不起作用?
【问题讨论】:
-
你为 CategoryComboBox.ItemsSource 设置了什么?
-
如果不设置 ItemsSource,则无法直接设置 SelectedItem。另请参阅this 回答,了解如何正确选择项目。