我有一个列表视图,该视图填充了我的会计科目表:
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
一词,而不显示实际选择的项目。
谁能解释为什么这不起作用?
答案 0 :(得分:0)
我认为您的答案是这样的:
CategoryComboBox.SelectedItem = Combox1.FindStringExact(SelectedCOA.Category.?) // ? = displayed cat name
或
CategoryComboBox.SelectedIndex = CategoryComboBox.Items.IndexOf(SelectedCOA.Category.?);