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

时间:2011-11-02 17:19:30

标签: c# winforms winapi telerik

我正在尝试启动下拉列表单击以获取MultiColumnComboBox类型的组合框(RadMultiColumnComboBox)。

我试图模仿的行为是当用户点击下拉列表的[v]按钮时,显示实际列表。

我的控件是Telerik.WinControls.UI.RadMultiColumnComboBox。

我在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 

似乎是一个可行的解决方案,但我不确定这对我的C#控件有什么作用。

我发现还有一个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);

如果有人熟悉WinForms ComboBox并且可以帮助我弄清楚如何启动Show Items / Elements / List事件(或其他任何名称),我真的很感激!

2 个答案:

答案 0 :(得分:2)

等效的c#是:

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

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

检查它是否适合您。

答案 1 :(得分:1)

如果我理解正确,您需要以编程方式打开下拉列表。如果是这种情况,请按以下步骤操作:

radMultiColumnComboBox1.MultiColumnComboBoxElement.ShowPopup();