【问题标题】:Set the ComboBox's SelectedItem to the object from ListBox UWP将 ComboBox 的 SelectedItem 设置为 ListBox UWP 中的对象
【发布时间】: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;
    }
}

问题是,我无法将CategorySubCategory 组合框设置为相关的CategorySubCategory。 ComboBox 仅显示 CategorySub Category 单词,而不是实际选中的项目。

谁能解释为什么这不起作用?

【问题讨论】:

标签: c# uwp


【解决方案1】:

我认为你的答案是这样的:

CategoryComboBox.SelectedItem = Combox1.FindStringExact(SelectedCOA.Category.?) // ? = displayed cat name

CategoryComboBox.SelectedIndex = CategoryComboBox.Items.IndexOf(SelectedCOA.Category.?);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 2016-05-15
    • 2017-04-30
    相关资源
    最近更新 更多