Question BindingNavigator disable button

rctaubert

Member
Joined
Aug 22, 2004
Messages
24
Programming Experience
10+
Can someone suggest how I can disable the various button on a BindingNavigator control??

For instance, if a user is adding a member I want to disable the Delete button and all of the Move arrows, plus the ability to change the Position number.

The same applies to clicking the Delete button. Diable the Add & Move buttons, etc.

I tried BindingNavigatorMoveFirstItem.Enabled = False but that has no affect that I can see. I can still click the movefirst arrow and move away.

And if anyone has a suggestion for how to accomplish this is someone begins an edit on a row I would appreciate it.

Thank you
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,570
Location
Sydney, Australia
Programming Experience
10+
The BindingNavigator manages the enabled state of its buttons itself, so if you navigate to the first record it will automatically disable the Move First and Move Previous buttons. If you explicitly set the Enabled property of any of the buttons then it will work, but as soon as you navigate again the control itself will again set the state of all the buttons, so your setting may be lost.

Can you explain what exactly you're trying to achieve and why the BindingNavigator's own behaviour isn't enough? Can you also show us the code you're using and explain exactly what happens when?
 

rctaubert

Member
Joined
Aug 22, 2004
Messages
24
Programming Experience
10+
Binding Navigator

I am writing a small membership app for a local historical society. None of them have a lot of computer knowledge.

I am trying to insure that they finish a task before they try to start another task or move away without clicking the Save button. The idea is if they click the Add button all other buttons are disabled untill the Save button is clicked.

I am beginning to believe it would be easier to just toss the BindingNavigator and do everything manually.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,570
Location
Sydney, Australia
Programming Experience
10+
I think you'll find that the problem is that you are setting Enabled to False before the navigation to the new row is complete, which means that the BindingNavigator will update the buttons itself afterwards.

If you want to override the default behaviour of the BindingNavigator then you will have to set all the properties that relate to the buttons to Nothing, e.g. set the MoveFirstItem property of the BindingNavigator to Nothing. You can then disable and enable the button as you like and the control will not override you. Just be aware that this means that you must take resposibility for ALL the behaviour of that button, i.e. you must enable and disable it as the user navigates to and from the first item in the list and you must also handle the Click event and call MoveFirst on the BindingSource explicitly. You can't have it both ways unfortunately. Either the BindingNavigator does all the work or you do all the work.
 

rctaubert

Member
Joined
Aug 22, 2004
Messages
24
Programming Experience
10+
Binding Navigator

Thank you for your help.

What I was hoping for was to be able to disable the buttons if the user clicked the ADD or DELETE button and then re-enable the when the user clicked the SAVE button.

The reason for this is the way the sequence of events seems to take place. You click ADD and input information then at some point you must click SAVE. The same with DELETING and MODIFING a record. At some point the User has to remember to click save. I want to force the issue with each ADD, DELETE or MODIFICATION.

With what you have told me and what I have been able to find I believe I will go back to the manual method as I always did with the Acess databases I wrote.

Thank you for your help.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,570
Location
Sydney, Australia
Programming Experience
10+
It's really not that difficult to do what you want with the BindingNavigator. It just means that you'll have to handle the appropriate events of the associated BindingSource and set the states of the items where normally the BindingNavigator would do it automatically.

That said, I don't it would be the best option in most cases. Forcing a user to save after each modification can be annoying. It's generally better to let them make as many changes as they want and then save them all as a batch. It's not that hard to check whether there are changes when they try to close the form and then prompt them to save then. That approach also makes it easier for the user to discard changes they don't want to keep.
 

rctaubert

Member
Joined
Aug 22, 2004
Messages
24
Programming Experience
10+
Binding Navigator

I find it is a choice between maybe annoying the user and protecting the data.

I would foresee a user making several additions, modifications and deletions and then, when presented with the "Save" request deciding they didn't really mean to delete Alfred E. Newman and saying NO. Now they have to redo everything else. I think they would find that even more inconvenient.

And there is always going to be someone that doesn't realize they said no to ALL of the changes and later wants to know why the db ate their data.

I have just always found it easier on them AND me to only allow them to do one thing at a time. I will have to give it some more thought.

Thanks again.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,570
Location
Sydney, Australia
Programming Experience
10+
I suggest you redesign your app not to navigate records, if you want them to do one thing at a time
True. A dedicated dialogue that handles one record at a time would the way to go if you want to handle one record at a time.
 

rctaubert

Member
Joined
Aug 22, 2004
Messages
24
Programming Experience
10+
Binding Navigator

Hi guys,

Thanks to you both for your input.

Correct me if I am wrong, but I believe I can do away with the BindingNavigator toolstrip, create my own and use the BindingSource to move between records.

Does that sound right???
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,570
Location
Sydney, Australia
Programming Experience
10+
Hi guys,

Thanks to you both for your input.

Correct me if I am wrong, but I believe I can do away with the BindingNavigator toolstrip, create my own and use the BindingSource to move between records.

Does that sound right???
Yes it does, but a BindingNavigator already uses a BindingSource to move between records so what do you gain by creating your own ToolStrip? By setting the properties I mentioned to Nothing you are basically turning the BindingNavigator into just a ToolStrip, but it already has all the correct buttons on it. Remember, the BindingNavigator IS a ToolStrip already, just with some extra functionality added. You're talking about creating your own, which would mean you have to implement all the enabling and disabling of buttons yourself. How does that differ from what I've already suggested with the BindingNavigator?
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
Well.. er.. you said you want the users to do one thing at once so why complicate their lives by allowing them to scroll records? Have a dialog that shows, edits, saves or forgets ONE record at a time. Use a searhc facility to get into it. Ensure it has no multiple records to scroll
 
Top Bottom