Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > BindingNavigator SaveItem_Click
 

BindingNavigator SaveItem_Click

I think I just need to implement the SaveItem_Click event in the BindingNavigator object, but there are certainly many ways to satisfy my requirements. The problem I am having with the the SaveItem button is that when I add a handler for the button,it remains disabled.

I created a class for the object I need to edit. I created a data source from the object. I dragged the data source to the form to create a DataGridView. I add data to the data source using BindingSource.Add. All that is amazingly easy, now that I know how to do it. My data never exists in a table or database.

The tasks to update the data is not easy, or at least the documentation is not easy to find. For controls bound to a TableAdapter, the updates get applied to the data source in memory and then the updates are saved to disk when the save button in the BindingNavigator is clicked. I can use equivalent functionality, but as I say, the SaveItem button remains disabled even when I add a handler for it.

My requirements are simple enough that I could simply use a DataGridView without a navigator or an unbound control and simply add a button or menu item to do the save, but I am trying to use the IDE and such as much as possible. The IDE and ADO and .Net should make what I am trying to do as easy as the parts I have already done, but if not then I don't mind writing whatever code I need to.

Sam Hobbs; see my SimpleSamples.Info
Simple Samples  Thursday, October 01, 2009 12:30 AM
Hi Simple,

Sorry for not getting the key problem. Have you checked the Enabled property of the Save item button? If it is false, we need to set it to true.
This is another thread shows how to use unbound BindingNavigator:
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/f7a5ae95-2c7d-41cd-89e2-2ef40e8eee89

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, October 08, 2009 5:29 AM

Hi Simple,

Sorry for did not express my ideas clearly. Actually, when we drag a DataTable onto the form to add a DataGridView, the designer does a lot of things. It would create a BindingNavigator on to the form and add a save button to it. Then bind a BindingSource(which is also bound to the DataGridView) to the BindingNavigator(by setting its BinidngSource property).

In most cases, the data source are a DataSet or a DataTable and it is mapped to a database. So the designer know how to handle the data updating to database. So it would enable the Save button and add a click event handler to it. But in your case, the data source is a list of objects. The designer cannot know how to persist data, so it does not enable the save button and add a handle to it. In this case, we need to enable the save button by ourselves and handle the click event handler by ourselves.

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  21 hours 20 minutes ago

Hi Simple,

You need to bind the data source to the BindingNavigator by setting its BindingSource property. You can follow the document below:
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingnavigator.bindingsource.aspx

Attention: the BindingSource of the DataGridView and the BindingNavigator ought to be the same.

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, October 02, 2009 9:33 AM
"I dragged the data source to the form to create a DataGridView."
Did I not "bind the data source to the BindingNavigator" and bind the data source to the BindingSource when I dragged the data source to the form?
Sam Hobbs; see my SimpleSamples.Info
Simple Samples  Friday, October 02, 2009 3:38 PM
Hi Simple,

If you drag a data souce on to the form and the BindingNavigator is automatically created, you did bind the data source to the BindingNavigator. If you drag a BindingNavigator control from the ToolBox onto the form, you need to set the BindingSource property of the BindingNavigator control.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, October 05, 2009 2:37 AM

As I said in my original question, I dragged the data source to the form.

Do you have an answer to my question? Did you read the question? So far, nothing in either reply tells me anything I did not already know. In other words, nothing yet helps to answer my question.


Sam Hobbs; see my SimpleSamples.Info
Simple Samples  Monday, October 05, 2009 3:42 AM
Hi Simple,

You said: The problem I am having with the the SaveItem button is that when I add a handler for the button, it remains disabled.
From my experience, the root cause of this issue is that the BindingSource of the BindingNavigator is not set. You need to check this.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, October 05, 2009 3:48 AM

I had so much difficulty getting the add/delete/update to work that I might have broke it. I doubt it, since the add and delete buttons always worked in this application to add a new row to the grid and to delete a row.

If you had been more clear in your original response saying that the BindingSource of the BindingNavigator might not be set, then I could have investigaet further but I have since given up on the use of objects bound to a grid using a BindingNavigator.

You can try this. Create a new C# forms applicaiton, then add a very simple class that just has a couple of properties or something simple such as that. Then add a data source for the object. The double-click the save item button to add a handler for it. Test it; note that the add and delete buttons work, but the save item button remains disabled.

It could be that the save item button does not do what I assumed it does, but that does not explain why it remains disabled. I have searched for documentation of the SaveItem button and I cannot find anything that helps.


Sam Hobbs; see my SimpleSamples.Info
Simple Samples  Monday, October 05, 2009 5:02 AM
Hi Simple,

Sorry for not getting the key problem. Have you checked the Enabled property of the Save item button? If it is false, we need to set it to true.
This is another thread shows how to use unbound BindingNavigator:
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/f7a5ae95-2c7d-41cd-89e2-2ef40e8eee89

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, October 08, 2009 5:29 AM

The BindingNavigator is not unbound; it has a data source bound to it, correct? I did not create the BindingNavigator directly; it was created indirectly when I dragged the grid from the data source to the form. Doesn't that bind the BindingNavigator to the data source? As I said in my previous reply, the BindingNavigator did affect the grid; doesn't that indicate that the BindingNavigator is bound to the data source?

Yes, enabling the button is all I had to do to get it to work. I did not do anything more; I did not bind the BindingNavigator. It is certainly easy to do when you know what to do but I sure don't know how I was supposed to know to do that. I would have expected that if a handler is added for the button, that it would be enabled. This might be another small detail that the Microsoft developers overlooked, at least in the design of Visual Studio.


Sam Hobbs; see my SimpleSamples.Info
Simple Samples  23 hours 10 minutes ago

Hi Simple,

Sorry for did not express my ideas clearly. Actually, when we drag a DataTable onto the form to add a DataGridView, the designer does a lot of things. It would create a BindingNavigator on to the form and add a save button to it. Then bind a BindingSource(which is also bound to the DataGridView) to the BindingNavigator(by setting its BinidngSource property).

In most cases, the data source are a DataSet or a DataTable and it is mapped to a database. So the designer know how to handle the data updating to database. So it would enable the Save button and add a click event handler to it. But in your case, the data source is a list of objects. The designer cannot know how to persist data, so it does not enable the save button and add a handle to it. In this case, we need to enable the save button by ourselves and handle the click event handler by ourselves.

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  21 hours 20 minutes ago
Thank you. I think this is another situation where Microsoft did not think through all the details. Thank you for explaining this. I hope this helps other developers too.
Sam Hobbs; see my SimpleSamples.Info
Simple Samples  13 hours 44 minutes ago
Hi Simple,

You are welcome.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  2 hours 58 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Error in Datagrid column style when setting the ReadOnly property to true!!!
• Binding System.Console with a TextBox
• Problem in DataGridView on DateTime column
• Update CheckBox Column based on another underlying column with an expression
• Problem Binding Objects
• DataGridViewComboBoxColumn bound to complex object
• datagridview cellvalidating event problem(Sevier problem)
• Send Mail Using VS03 and Windows Application
• InsertCommand that loop DataGridView Rows.
• Nullable Int - Databinding to TextBox vs. UserControl