c# - 将 ComboBox 的 SelectedItem 设置为 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
andSubCategory
组合框设置为相关的Category
and SubCategory
。ComboBox 只显示Category
和Sub Category
单词,而不是实际选择的项目。
谁能解释为什么这不起作用?
解决方案
我认为你的答案是这样的:
CategoryComboBox.SelectedItem = Combox1.FindStringExact(SelectedCOA.Category.?) // ? = displayed cat name
或者
CategoryComboBox.SelectedIndex = CategoryComboBox.Items.IndexOf(SelectedCOA.Category.?);
推荐阅读
- angular - 如果不使用默认值,则 Angular @HostListener 延迟单击直到给出输入
- android - 在 MainActivity 内的导航主机片段上调用方法
- groovy - Spock“then”块下的魔法是什么?
- html - foo滚动不起作用,但在新选项卡中打开时,页面在 id="thisSection" 处加载
- java - Rest API 服务器容错
- ffmpeg - 如何正确转换 ffmpeg 中的 RTL 字幕?
- javascript - TypeScript:将字符串转换为对象
- mongodb - 如何计算聚合中 $groups 的数量?
- c++ - 编译原生 Windows 10 应用程序中的 Visual c++ 问题
- jquery - 如何将数组传递给 AJAX