选择项目后如何使组合框保持打开状态?

发布于 2024-10-17 02:29:51 字数 79 浏览 2 评论 0原文

在 C# 中选择某个项目后,如何使组合框保持打开状态?

我想这样做是因为它实际上是一个带有清单的组合框,因此我可以选择多个项目。

How do I make a combobox stay open after an item is selected in C#?

I want to do this because it is actually a comboBox with a checklist so I can select several items.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

西瑶 2024-10-24 02:29:51

使用 ListBox 代替,因为 ComboBox 通过其核心设计来实现这种行为。

ListBox 提供了类似的效果(因此它仍然打开)并支持多重选择。

Use ListBox instead, since ComboBox does that behavior by its core design.

ListBox gives a similar effect (hence it is still open) and enabling for multi-selection.

番薯 2024-10-24 02:29:51

如果您仍然希望允许用户编写自己的选项,您仍然可以使用 DropBox,只需将 DropDownStyle 属性设置为 simple 即可。您将得到与列表框类似的内容,但顶部有一个文本框,用户可以在其中编写一些内容。

If you still want to allow the user to write an option of his own you can still use a DropBox, just set the DropDownStyle property to simple. You'll get something similar with a ListBox but with an TextBox on the top where the user can write somwthing.

酒解孤独 2024-10-24 02:29:51

使用ListBox而不是ComboBox。您想要做的事情(即使在用户选择了一个选项后仍保持组合框打开)将是不寻常和意外的行为。

更新:我认为这个示例可以让您做您想做的事情(即拥有一个只占用一个控件的表单空间的多选列表):

http://www.codeguru.com/csharp/csharp/cs_controls/treeview/article.php /c15373/

Use a ListBox instead of a ComboBox. What you want to do (keep a ComboBox open even after the user has selected a choice) would be unusual and unexpected behavior.

Update: I think this sample will let you do what you want (which is to have a multi-select list that only takes up the form real estate of one control):

http://www.codeguru.com/csharp/csharp/cs_controls/treeview/article.php/c15373/

晨曦÷微暖 2024-10-24 02:29:51

此功能在 .NET 3.0 及更高版本中可用。使用 ComboBox.StaysOpenOnEdit 属性

This functionality is available in .NET 3.0 and beyond. Use the ComboBox.StaysOpenOnEdit property

灯角 2024-10-24 02:29:51

虽然我意识到这个问题是针对 winforms 的,但请允许我为 wpf 寻求者提供一个答案(实际上,正如我到达这里的那样)。

只需将类似的内容放入组合框中即可。

<Grid>
    <ComboBox Width="1" Height="1" IsDropDownOpen="{Binding ElementName=TButton,Path=IsChecked,Mode=TwoWay}">
        <Grid Width="200" Height="400" Background="BlanchedAlmond" Margin="-5" IsHitTestVisible="True">
            <Button Background="Transparent"></Button> <--------- This is the equivalent of a e.handled
            <StackPanel>
                <Button Content="Button 1"/>
                <Button Content="Button 1"/>
                <Button Content="Button 1"/>
                <Button Content="Button 1"/>
            </StackPanel>
        </Grid>
    </ComboBox>
   <ToggleButton x:Name="TButton" Content="Drop" MaxHeight="40" MaxWidth="40"/>
</Grid>

快速而肮脏的修复,以获得体面、无麻烦的下拉控制。

当您单击组合框项目时,您实际上单击了不可见的按钮,并且组合保持打开状态。

我尝试过使用最热门的可见矩形,但没有骰子。这可以解决问题。

注意


应将不可见背景替换为完全剥离按钮的样式(当鼠标悬停或执行单击时)。

另外,使用下拉字体图标/路径而不是drop会很好。 :)

我再次为在这里发帖道歉。我一直在到处寻找一个具有 0 个外部依赖项的快速下拉控件(弹出窗口不会这样做),而我偶然发现的都是可笑的(不必要的)复杂的实现。我希望这能引导某人走向正确的方向!

祝你好运!

编辑
简单的不透明度 0 就可以了。嚯……

While I realize the question was intended for winforms, please allow me to contribute an answer for wpf seekers(as I got here, actually).

simply put something like this in the combo box.

<Grid>
    <ComboBox Width="1" Height="1" IsDropDownOpen="{Binding ElementName=TButton,Path=IsChecked,Mode=TwoWay}">
        <Grid Width="200" Height="400" Background="BlanchedAlmond" Margin="-5" IsHitTestVisible="True">
            <Button Background="Transparent"></Button> <--------- This is the equivalent of a e.handled
            <StackPanel>
                <Button Content="Button 1"/>
                <Button Content="Button 1"/>
                <Button Content="Button 1"/>
                <Button Content="Button 1"/>
            </StackPanel>
        </Grid>
    </ComboBox>
   <ToggleButton x:Name="TButton" Content="Drop" MaxHeight="40" MaxWidth="40"/>
</Grid>

Quick and dirty fix for a decent, hassle free drop down control.

When you click the combobox item, you actually click the invisible button and the combo stays open.

I've tried with a hittest visible rect, but no dice. This does the trick.

Note


One should replace the invisible background with a style that completely strips the button (when mouse is over or a click is performed).

Also, a drop font icon / path instead of drop would be nice. :)

I apologize again for posting here. I've been looking all over the place for a quick drop down control with 0 outside dependencies(popup won't do) and all I've stumbled across are ridiculously (needlessly) complicated implementations. I hope this will steer somebody in the right direction!

Best of luck to you!

Edit
A simple opacity 0 will do. Doh...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文