我有一个工具条。对于这个工具条,我加入 ToolStripSplitButton
并为此的 ToolStripSplitButton
,我加入工具条的物品,其中包括的 ToolStripSeparator
。在工具条项的单击事件,我从 ToolStripSplitButton
使用下面code下拉列表。
I have a toolstrip. For this toolstrip, I am adding ToolStripSplitButton
and for this ToolStripSplitButton
, I am adding toolstrip items, including ToolStripSeparator
. In the click event of the toolstrip items I am retrieving items from the ToolStripSplitButton
dropdown using below code.
ToolStripDropDown tditems = ((System.Windows.Forms.ToolStripDropDownItem)(items[0])).DropDown;
foreach (ToolStripMenuItem item in tditems.Items)
{
//something here
}
随着下拉项具有两个工具条的项目和 ToolStripSeparator
在运行时,它给下面的错误。
As the dropdown items have both toolstrip items and ToolStripSeparator
at runtime, it is giving following error.
信息:无法施放 类型的对象 System.Windows.Forms.ToolStripSeparator 输入 System.Windows.Forms.ToolStripMenuItem。
Additional information: Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripMenuItem'.
任何人可以帮助我吗?
感谢
推荐答案
如果您使用的是.NET 3.5,你可以使用的 OfType
扩展方法如下:
If you are using .NET 3.5, you could use the OfType
extension method as follows.
foreach (var item in tditems.Items.OfType<ToolStripMenuItem>())
{
// something here
}
相关推荐
最新文章