SplitButton event ERROR. Not triggering the toolstripitem click event.

Hi, guys.

The SplitButton component is not triggering the Click event in the toolstripitem.

my code is like this:

var toolStripItem = new toolstripitem()
{
Text = "Add",
Image = imageList.Images["Add"]
};

toolStripItem.Click+= MethodToExecuteWhenClickOnItem;
splitButton.DropDownItems.Add(toolStripItem);
When I click on the item, the click event does not fire.

Am I missing something?

Thanks.

3 Replies 1 reply marked as answer

EM Elakkiya Muthukumarasamy Syncfusion Team February 24, 2021 10:28 AM UTC

Hi Marlon, 
  
Thanks for contacting Syncfusion support. 
  
We have checked your reported query and suspect that you are trying to add toolstripitem as drop down item in the splitButton.Our recommended approach to use ToolStripMenuItem as drop down item.Please refer the UG documentation link below, 
  
  
Please try it with the provided solution and let us know if you need any further assistance on this. 
  
Regards, 
Elakkiya 



MA Marlon Assef February 24, 2021 09:25 PM UTC

Hi, Elakkiya.

Thank you for the quick reply.

According to the documentation, the ToolStripMenuItem is a menu item for ToolStripDropDownButton in the RibbonControlAdv.

Unfortunately that's not the case.

We do not use the RibbonControlAdv, actually, we use a SplitButton on the form close to a text box (see image below) and the items for SplitButton are toolstripitem as described in the code previously. Also, if changed to ToolStripMenuItem the code does not compile.



Please let me know if you need more details.

Regards.



EM Elakkiya Muthukumarasamy Syncfusion Team February 25, 2021 01:32 PM UTC

 
Hi Marlon, 
 
Sorry for the inconvenience. 
 
On further validating, mentioned issue “While using ToolStripItem as dropdown item of SplitButton click event not fired “ is reproduced and we have recommended to use SplitButton DropDownItemClicked event to customize the ToolStripItem. Please refer the below sample and code example for the same. 
 
Code snippet: 
 
private void SplitButton1_DropDowItemClicked(object sender, ToolStripItemClickedEventArgs e) 
{ 
var  t = e.ClickedItem; 
if(t != null && e.ClickedItem.Text == splitButton1.DropDownItems[0].Text) 
{ 
e.ClickedItem.Image = Bitmap.FromFile(@"../../help.png"); 
t = e.ClickedItem; 
} 
 
} 
 
 
Please try it with the provided solution and let us know if you need any further assistance on this. 
 
Regards, 
Elakkiya 


Marked as answer
Loader.
Up arrow icon