简体   繁体   English

如何在WinForms(Telerik)中显示ComboBox的下拉列表

[英]How to show the DropDown list of a ComboBox in WinForms (Telerik)

I'm trying to initiate the drop down list click for a combobox of type MultiColumnComboBox (RadMultiColumnComboBox). 我试图启动下拉列表,单击类型为MultiColumnComboBox(RadMultiColumnComboBox)的组合框。

The behavior I'm trying to emulate is when the user clicks the [v] button of the drop down, which shows the actual list. 我要模拟的行为是当用户单击下拉列表中的[v]按钮时,该按钮显示了实际列表。

My control is a Telerik.WinControls.UI.RadMultiColumnComboBox. 我的控件是Telerik.WinControls.UI.RadMultiColumnComboBox。

I saw a post on the Telerik forums suggesting to do something like this: 我在Telerik论坛上看到一篇帖子建议做这样的事情:

Dim item As RadTextBoxItem =     TryCast(Me.radMultiColumnComboBox1.MultiColumnComboBoxElement.Children(2).Children(0).Children(0), RadTextBoxItem) 

 If item IsNot Nothing Then 
     AddHandler item.Click, AddressOf OnTextBoxItem_Click 
 End If 

Seems like a viable solution, but I'm not sure how this would work on my C# control. 似乎是一个可行的解决方案,但是我不确定这在C#控件上如何工作。

There is also a Win32 hack I found, but this would not pass code review: 我发现还有一个Win32 hack,但这不会通过代码审查:

// Declare the following in your class

[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, int msg, int wParam, IntPtr lParam);
 public const int CB_SHOWDROPDOWN = 0x14F;

 // In the leave event of combobox, use the following code:

  SendMessage(comboBox1.Handle.ToInt32(), CB_SHOWDROPDOWN, 1, IntPtr.Zero);

If anyone is familiar with a WinForms ComboBox and can help me figure out how to kick off the Show Items/Elements/List event (or whatever its called), I'd really appreciate it! 如果有人熟悉WinForms ComboBox并且可以帮助我弄清楚如何启动Show Items / Elements / List事件(或其他任何名称),我真的很感激!

The equivalent c# is: 等效的c#是:

RadTextBoxItem item = this.radMultiColumnComboBox1.MultiColumnComboBoxElement.Children(2).Children(0).Children(0) as RadTextBoxItem;

if (item != null) {
    item.Click += OnTextBoxItem_Click;
}

Check if it works for you. 检查它是否适合您。

If I understand correctly, you want to open the drop down programatically. 如果我理解正确,你想以编程方式打开下拉列表。 If this is the case, here is how you can do that: 如果是这种情况,请按以下步骤操作:

radMultiColumnComboBox1.MultiColumnComboBoxElement.ShowPopup();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM