1

I want to use the default delete button (if possible) but instead of that button calling its default click event, I want to call my own event. I know how to get it to call my own event but I don't know how to eliminate it from also calling its default event. I don't know what the default event is called in order to remove it. Anyone know? Same question for the default add item's click event. What is the default add button's click event called?

Here is a pic of the tool strip that was added when I dropped the data source on to the form. It is the events of these add and delete buttons I refer to: tool strip

Here is the code I am working with:

this.bindingNavigatorDeleteItem.Click -= WhatGoesHere?;
this.bindingNavigatorDeleteItem.Click += myDeleteClickEventHandler;
  • I am not sure what you are trying to refer to when you talk about the default add and delete buttons in relation to a DataGridView; the DataGridView does not contain any buttons by default. Could you please give a pictorial example or a code snippet referring to the objects in question? – Nathan Van Dyken Jan 30 '18 at 16:23
  • Sorry for being incomplete. Edited to include tool strip image – JimOfTheNorth Jan 30 '18 at 16:31
  • Just delete it and add your own. – LarsTech Jan 30 '18 at 16:51
  • that is not my preference but may be the only option if I can't override the default event. – JimOfTheNorth Jan 30 '18 at 17:05

1 Answers1

1

From within the designer, highlight the ToolStrip, and go to DeleteItem in the Properties window and select none:

enter image description here

or from code:

bindingNavigator1.DeleteItem = null;

Now you can add your own event as you wish.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • Thanks for that. I tried your code approach previously but it just greys-out the delete button on the tool strip. Adding my own event (using the code shown in my original question) has no effect with the button greyed-out. – JimOfTheNorth Jan 30 '18 at 18:03
  • @JimOfTheNorth You are doing something I can't see. My delete button did not get grayed out. Make sure the ToolStrip and the button are both enabled, the ToolStrip is using a BindingSource, and you have data. – LarsTech Jan 30 '18 at 18:09
  • thanks for the additional follow-up. This time I tried setting the delete item property to "none" from the designer, instead of in code.It worked great! So what I need now, is to clarify the approach in code. Did you try your code suggestion? By the way, when I used the code you suggested, I put it in the constructor of my form.cs after the call to `InitializeComponent()` – JimOfTheNorth Jan 30 '18 at 18:42
  • <> sorry...that sounded a little obtuse...not meant that way. – JimOfTheNorth Jan 30 '18 at 19:02
  • @JimOfTheNorth Yes, I am running that posted code in the form's constructor. I can't reproduce your issue. – LarsTech Jan 30 '18 at 19:58
  • Thanks for that. I tried the code again. must have been doing something wrong the first couple of attempts because it works fine now. Thanks very much for your assistance!! PS: How did you get a screen shot of the toolstrip properties dropdown without the list of options disappearing? Jeeze...I tried to mark your answer as accepted but i guess I don't have enough points yet. :( – JimOfTheNorth Jan 30 '18 at 20:10
  • @JimOfTheNorth Hit the Print-Screen button, crop in Paint.net. – LarsTech Jan 30 '18 at 20:12