簡體   English   中英

將ComboBox的SelectedItem設置為ListBox UWP中的對象

[英]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;
    }
}

問題是,我無法將CategorySubCategory框設置為相關的CategorySubCategory 組合框僅顯示CategorySub 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM