[英]Set the ComboBox's SelectedItem to the object from ListBox UWP
我有一個填充我的會計科目表的列表視圖:
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
。 組合框僅顯示Category
和Sub Category
詞,而不顯示實際選擇的項目。
誰能解釋為什么這行不通?
我認為您的答案是這樣的:
CategoryComboBox.SelectedItem = Combox1.FindStringExact(SelectedCOA.Category.?) // ? = displayed cat name
要么
CategoryComboBox.SelectedIndex = CategoryComboBox.Items.IndexOf(SelectedCOA.Category.?);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.