|
Hi,
I'm using a DataGridView to display all my data and another form to insert and edit items. To be more productive I'm using BindingNavigator, but I don't know how can I navigate to the row that the user asked to edit on the DataGridView.
How can I do this? http://blogs.julianonunes.com (Português) | http://weblogs.asp.net/julianonunes (English)
http://twitter.com/julianonunes | http://www.linkedin.com/in/julianonunes | http://www.facebook.com/julianonunes | | Juliano Nunes Tuesday, August 04, 2009 11:30 PM | Hello Juliano, >When the form is opened, the bindingsource is changed to "insert mode", but if the user navigates or leaves the form, he receives an error indicating that a not null field has not been filled. In this case, I would like to prevent users navigating to other rows and provide a cancel button to let users exit the "insert mode". To prevent users navigating to other rows, we can disable the corresponding BindingNavigator buttons. See the following code for example http://social.msdn.microsoft.com/forums/en-US/winforms/thread/0c4dff32-da74-4697-a581-f808d2b8c333/ Thanks, MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer byJuliano Nunes Thursday, August 13, 2009 11:42 AM
-
| | Rong-Chun Zhang Friday, August 07, 2009 6:13 AM | You need to change the position of the BindingSource in question (the BindingSource associated with your BindingNavigator). You can use the Find method to figure out what position number should be used based on what you see in the grid.
int pos = bindingSourceAssociatedWithNavigator.Find("PrimaryKeyColumnName", yourDataGridView.CurrentRow.Cells["PrimaryKeyCell"].Value);
if (pos < 0)
throw new Exception();
bindingSourceAssociatedWithNavigator.Position = pos;
| | BinaryCoder Tuesday, August 04, 2009 11:49 PM | Hello Juliano, Apart from BinaryCoder's suggestion, I would like to suggest you binding the DataGridView and BindingNavigator to the same BindingSource, then the DataGridView and BindingNavigator will keep synchronized. We can also use the BindingSource.Filter to filter which rows are available to view on the DataGridView, then users can easily navigate to the row they want to edit. For example: bindingSourceAssociatedWithNavigator.Filter = "columnname like '" + filterstring + "*'"; More information, http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter.aspx http://windowsclient.net/blogs/faqs/archive/2006/07/12/why-doesn-t-my-datagrid-control-stay-in-sync-with-my-textbox-control.aspx Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Edited byRong-Chun ZhangMSFT, ModeratorWednesday, August 05, 2009 8:57 AMadding link
-
| | Rong-Chun Zhang Wednesday, August 05, 2009 8:54 AM | Another question. Using BindingNavigator when the form is opened the user must clickon theAdd New button to put the form in Insert Mode, but the user of my application wants to open the form already in Insert Mode.
So I went to Form_loadand added bindingSource.AddNew(), but if I'm inserting a row and the first control to be edited is a ComboBox, the entire form stops and we aren't able to edit the other controls.
Thanks. http://blogs.julianonunes.com (Português) | http://weblogs.asp.net/julianonunes (English)
http://twitter.com/julianonunes | http://www.linkedin.com/in/julianonunes | http://www.facebook.com/julianonunes | | Juliano Nunes Thursday, August 06, 2009 4:54 AM | Hello Juliano, When you say the entire form stops and we aren't able to edit the other controls, did you mean that you cannot navigate to other control on the detailed form, the focus keep on the ComboBox? Please correct me if there is any misunderstanding. It seems that your data source has some data constraints, and the date inputted to ComboBox didn't march the constaints, ant then the focus cannot be moved to other controls. The following code can help us to check if there is any error in our binding object. this.comboBox1.DataBindings.Add(binding); binding.BindingComplete += new BindingCompleteEventHandler(binding_BindingComplete); void binding_BindingComplete(object sender, BindingCompleteEventArgs e) { if (e.Exception != null) { MessageBox.Show("You got a error"); e.Cancel = true; } } More information: http://social.msdn.microsoft.com/Forums/en-us/winformsdatacontrols/thread/a43aca3c-fd62-42fc-8867-2e13912dfa1c The above information is my understanding about your issue. To make it more precise, could you please share the source code and the detailed steps to reproduce the problem, so that we can investigate the issue locally. It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it. I appreciate your work on providing these information. Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Rong-Chun Zhang Thursday, August 06, 2009 8:35 AM | Zhang, Sorry for the delay answeering you. The problem is that when you Drag-and-Drop a datasource column that will render as a ComboBox and its items are fixed initially, so it adds two bindings, one for SelectedValue and another for Text property. Now this ComboBox is bound to another datasource and the Text Property must not be binded to the main datasource. But I have another problem. When the form is opened, the bindingsource is changed to "insert mode", but if the user navigates or leaves the form, he receives an error indicating that a not null field has not been filled. Which event can I use to find if the changes has not been persisted and ask the user if he wants to cancel or not? http://blogs.julianonunes.com (Português) | http://weblogs.asp.net/julianonunes (English)
http://twitter.com/julianonunes | http://www.linkedin.com/in/julianonunes | http://www.facebook.com/julianonunes | | Juliano Nunes Thursday, August 06, 2009 11:23 AM | Hello Juliano, >When the form is opened, the bindingsource is changed to "insert mode", but if the user navigates or leaves the form, he receives an error indicating that a not null field has not been filled. In this case, I would like to prevent users navigating to other rows and provide a cancel button to let users exit the "insert mode". To prevent users navigating to other rows, we can disable the corresponding BindingNavigator buttons. See the following code for example http://social.msdn.microsoft.com/forums/en-US/winforms/thread/0c4dff32-da74-4697-a581-f808d2b8c333/ Thanks, MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer byJuliano Nunes Thursday, August 13, 2009 11:42 AM
-
| | Rong-Chun Zhang Friday, August 07, 2009 6:13 AM | Hello Juliano, I am writing to check the status of the issue on your side. Would you mind letting me know the result of the suggestions? If you have any additional question, welcome to post here. Have a great day! Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Rong-Chun Zhang Thursday, August 13, 2009 3:11 AM | Sorry Zhang. Question marked as answered.
http://blogs.julianonunes.com (Português) | http://weblogs.asp.net/julianonunes (English)
http://twitter.com/julianonunes | http://www.linkedin.com/in/julianonunes | http://www.facebook.com/julianonunes | | Juliano Nunes Thursday, August 13, 2009 11:42 AM |
|