如何在DevExpress ComboBoxEdit中设置索引?

发布于 2024-12-13 11:33:02 字数 1255 浏览 1 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吲‖鸣 2024-12-20 11:33:03

编辑器设置(例如 ComboBoxEditSettings)中没有 SelectedIndex 或 SelectedItem 属性。
但是您可以设置 SelectedIndex、SelectedItem 或 EditValue 属性/documentation.devexpress.com/#WPF/clsDevExpressXpfEditorsComboBoxEdittopic" rel="nofollow">ComboBoxEdit 通过编辑器样式:

<dxb:BarEditItem x:Name="beiComboBox">
    <dxb:BarEditItem.EditStyle>
        <Style TargetType="dxe:ComboBoxEdit">
            <Setter Property="SelectedIndex" Value="1"/>
        </Style>
    </dxb:BarEditItem.EditStyle>
    <dxb:BarEditItem.EditSettings>
        <dxe:ComboBoxEditSettings>
            <dxe:ComboBoxEditSettings.Items>
                <dxe:ComboBoxEditItem>AAA</dxe:ComboBoxEditItem>
                <dxe:ComboBoxEditItem>BBB</dxe:ComboBoxEditItem>
                <dxe:ComboBoxEditItem>CCC</dxe:ComboBoxEditItem>
            </dxe:ComboBoxEditSettings.Items>
        </dxe:ComboBoxEditSettings>
    </dxb:BarEditItem.EditSettings>
</dxb:BarEditItem>

如果捕获 Loaded 事件,您还可以从代码隐藏设置 ComboBoxEdit.SelectedIndex 属性:

<dxb:BarEditItem.EditStyle>
    <Style TargetType="dxe:ComboBoxEdit">
        <EventSetter Event="Loaded" Handler="ComboBoxEdit_Loaded"/>
    </Style>
</dxb:BarEditItem.EditStyle>

//...
void ComboBoxEdit_Loaded(object sender, RoutedEventArgs e) {
    ((ComboBoxEdit)sender).SelectedIndex = 1;
}

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:

<dxb:BarEditItem x:Name="beiComboBox">
    <dxb:BarEditItem.EditStyle>
        <Style TargetType="dxe:ComboBoxEdit">
            <Setter Property="SelectedIndex" Value="1"/>
        </Style>
    </dxb:BarEditItem.EditStyle>
    <dxb:BarEditItem.EditSettings>
        <dxe:ComboBoxEditSettings>
            <dxe:ComboBoxEditSettings.Items>
                <dxe:ComboBoxEditItem>AAA</dxe:ComboBoxEditItem>
                <dxe:ComboBoxEditItem>BBB</dxe:ComboBoxEditItem>
                <dxe:ComboBoxEditItem>CCC</dxe:ComboBoxEditItem>
            </dxe:ComboBoxEditSettings.Items>
        </dxe:ComboBoxEditSettings>
    </dxb:BarEditItem.EditSettings>
</dxb:BarEditItem>

You can also set a ComboBoxEdit.SelectedIndex property from codebehind if you catch the Loaded event:

<dxb:BarEditItem.EditStyle>
    <Style TargetType="dxe:ComboBoxEdit">
        <EventSetter Event="Loaded" Handler="ComboBoxEdit_Loaded"/>
    </Style>
</dxb:BarEditItem.EditStyle>

//...
void ComboBoxEdit_Loaded(object sender, RoutedEventArgs e) {
    ((ComboBoxEdit)sender).SelectedIndex = 1;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文