如何在DevExpress ComboBoxEdit中设置索引?
如何在 DevExpress ComboBoxEdit
中“设置”SelectedIndex
?
我在 XAML 和后面的代码中都尝试过,但索引未设置,它以空白项开始。
我的 XAML: [我不明白为什么这不起作用,但它不起作用..]
<dxb:BarEditItem.EditSettings>
<dxe:ComboBoxEditSettings>
<dxe:ComboBoxEditSettings.Items>
<dxe:ComboBoxEditItem IsSelected="True">AAA</dxe:ComboBoxEditItem>
<dxe:ComboBoxEditItem>BBB</dxe:ComboBoxEditItem>
<dxe:ComboBoxEditItem>CCC</dxe:ComboBoxEditItem>
</dxe:ComboBoxEditSettings.Items>
</dxe:ComboBoxEditSettings>
</dxb:BarEditItem.EditSettings>
我的 C# 代码:
[我得到countStr 正确,所以我确定 ComboBoxEdit
和项目已初始化并添加正常,但 SelectedIndex
仍然没有设置索引。 .]
* 另外我不想使用 EditValue
来设置值,我需要使用整数(Index)来设置它。
private void Foo_LinkControlLoaded(object sender,
DevExpress.Xpf.Bars.BarItemLinkControlLoadedEventArgs e)
{
BarEditItemLink link = (BarEditItemLink)sender;
countStr = ((ComboBoxEdit)link.Editor).Items.Count.ToString();
((ComboBoxEdit)link.Editor).SelectedIndex = 2;
}
How to "Set" the SelectedIndex
in DevExpress ComboBoxEdit
?
I tried both in XAML and in code behind, but the index was not set, it starts out with a blank item.
My XAML: [I can't see why this doesn't work, but it doesn't..]
<dxb:BarEditItem.EditSettings>
<dxe:ComboBoxEditSettings>
<dxe:ComboBoxEditSettings.Items>
<dxe:ComboBoxEditItem IsSelected="True">AAA</dxe:ComboBoxEditItem>
<dxe:ComboBoxEditItem>BBB</dxe:ComboBoxEditItem>
<dxe:ComboBoxEditItem>CCC</dxe:ComboBoxEditItem>
</dxe:ComboBoxEditSettings.Items>
</dxe:ComboBoxEditSettings>
</dxb:BarEditItem.EditSettings>
My C# code:
[I'm getting the countStr correctly so I'm sure the ComboBoxEdit
and the items are initialized and added ok, but SelectedIndex
still don't set the index..]
* also I do not want to use EditValue
to set the value, I need to use an integer (Index) to set it.
private void Foo_LinkControlLoaded(object sender,
DevExpress.Xpf.Bars.BarItemLinkControlLoadedEventArgs e)
{
BarEditItemLink link = (BarEditItemLink)sender;
countStr = ((ComboBoxEdit)link.Editor).Items.Count.ToString();
((ComboBoxEdit)link.Editor).SelectedIndex = 2;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑器设置(例如 ComboBoxEditSettings)中没有 SelectedIndex 或 SelectedItem 属性。
但是您可以设置 SelectedIndex、SelectedItem 或 EditValue 属性/documentation.devexpress.com/#WPF/clsDevExpressXpfEditorsComboBoxEdittopic" rel="nofollow">ComboBoxEdit 通过编辑器样式:
如果捕获 Loaded 事件,您还可以从代码隐藏设置 ComboBoxEdit.SelectedIndex 属性:
There are no SelectedIndex or SelectedItem property within the editor settings (e.g. ComboBoxEditSettings).
But you can set the SelectedIndex, SelectedItem or EditValue properties of ComboBoxEdit via the editor style:
You can also set a ComboBoxEdit.SelectedIndex property from codebehind if you catch the Loaded event: