| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
|
|
| |
|
Linda Liu[MSFT]
Guest
Posts: n/a
|
Hi,
I notice that the AddEditMasterTask class inherits from the bsfAddEdit class in your sample code. However, the definition of the bsfAddEdit class isn't provided in your first message. Could you please create a simple application that could just reproduce the problem and send it to me? To get my actual email address, remove 'online' from my displayed email adress. Thank you for your understanding and cooperation! Sincerely, Linda Liu Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
|
||
|
||||
|
Linda Liu[MSFT]
Guest
Posts: n/a
|
Hi Douglas,
I have sent you a sample project to your email box. If there's any question, please feel free to let me know. Sincerely, Linda Liu Microsoft Online Community Support |
|
||
|
||||
|
dbuchanan
Guest
Posts: n/a
|
Linda,
Thank you for sending me the sample. =========================== Your application contains the same bug: By-the-way your sample behaves in identical fashion as my application with only one snall difference - since your sample allows nulls no error is thrown. ======================= A walk-thorugh to repeat the bug: I can walk you through two scenarios that will both repeat the behavior. Scenario 'A' uses the keyboard only to repeat the problem and scenario 'B' makes use of the mouse to repeat the behavior. -------------------------- Scenario 'A' keyboard only -------------------------- Start the project - Form1 opens Click 'add' button - Form2 opens Enter 1 for the ID Tab to go to the Measure dropdown box On your keyboard click the down arrow to select "area" Notice that the Unit control now displays "inch^2" click 'save' button Note the new record displays no value for the Unit column (You may continue to Scenario 'B' without closing) -------------------------- Scenario 'B' with mouse -------------------------- Click 'add' button - Form2 opens Enter 2 for the ID Click on the dropdown arrow for the Measure control and select "linear" Notice unit now displays "inch" click 'save' button Note the new record displays no value for the Unit column ================ Essential considerations: This situation only occurs if the desired Unit value happens to be the one displayed immediately after the Measuer column is selectd. And to prevent the problem the user has only to deliberately re-select the Unit value that is already shown. ======= Questions: 1.) Why does the populated control in the data entry form not result in data being entered into the dataset and thus the record in the data grid view? 2.) What is the work-around to make the binding to behave as designed? Douglas |
|
||
|
||||
|
Linda Liu[MSFT]
Guest
Posts: n/a
|
Hi Douglas,
Thank you for your reply and the detailed description! I understand your problem now. > 1.) Why does the populated control in the data entry form not result in data being entered into the dataset and thus the record in the data grid view? When we select the "area" item in the ComboBox1 in the Form2, "inch^2" is selected and displayed in the ComboBox2. However, the SelectedValueChanged event of the ComboBox2 is not fired at this time, so the new value is not pushed back to the data source by data binding. > 2.) What is the work-around to make the binding to behave as designed? The workaround is simple, i.e. call the WriteValue method of the corresponding Binding object to force the new value to be pushed back to the data source. The following is a sample: public partial class Form2 : Form { ... private void button1_Click(object sender, EventArgs e) { // add this line of code to force the new value to be pushed back to the data source this.comboBox2.DataBindings["SelectedValue"].WriteValue(); this.BindingContext[ds, "DataTable1"].EndCurrentEdit(); this.Close(); } } Hope this helps. If you have anything unclear, please feel free to let me know. Sincerely, Linda Liu Microsoft Online Community Support |
|
||
|
||||
|
dbuchanan
Guest
Posts: n/a
|
Linda,
Thank you so much for your reply and great explaination! There seems to be so many little things that one cannot discover while working with Visual Studio. I am luck to have a lot of books available to me, but books do not seem to cover the sorts of things I run into. I do great on C# of VB tests, but when it comes to using the product in the real world... I go so far and get stuck. Go a little more and get stuck. I wish using the product were just a little bit more intuative or discoverable. Are there any books or other learning resources you could suggest to help me, as they call it, "get it"? Thanks, Doug |
|
||
|
||||
|
Linda Liu[MSFT]
Guest
Posts: n/a
|
Hi Doug,
Thank you for your feedback! You may refer to the following MSDN document for more information on data binding: 'Windows Forms Data Binding' http://msdn2.microsoft.com/en-us/library/ef2xyb33(VS.80).aspx If you have any question in the future, please feel free to post in the newsgroup. We will be glad to work with you to get the problems solved : ) Sincerely, Linda Liu Microsoft Online Community Support |
|
||
|
||||
|
dbuchanan
Guest
Posts: n/a
|
Linda,
I have tried to implement your suggestion but without success. I believe it has to do with the different ways that we bind. Where you use EndCurrentEdit with BindingContext I use EndEdit with BindingSource. Here is your code (for the benefit of others): > public partial class Form2 : Form > { > ... > private void button1_Click(object sender, EventArgs e) > { > // add this line of code to force the new value to be pushed > back to the data source > this.comboBox2.DataBindings["SelectedValue"].WriteValue(); > this.BindingContext[ds, "DataTable1"].EndCurrentEdit(); > this.Close(); > } > } Here is my attempt to implement it with my approach (pertinent statements only): private void btnSave_Click(object sender, EventArgs e) { // Force the displayed the child combobox value to be pushed back to the data source this.fkMeasureDimIDComboBox.DataBindings["SelectedValue"].WriteValue(); // for reference - if my situation were similar to Linda's... // this.BindingContext[dataSetHipAdmin, "MTask"].EndCurrentEdit(); // Apply pending changes to the underlying data source bsMTask.EndEdit(); // Send changes back to the database taMTask.Update(dataSetHipAdmin.MTask); this.Close(); } ========================== More on my approach: I do not refer to or use BindingContext or CurrencyManager in my project. Rather I approach it this way... Here are a few statements to show how I use the BindingSource ("bsMTask") and TableAdapter ("taMTask") for table ("MTask") in the child form - the form of interest. In the constructor I populate the controls on the form this way (when the form is opened to editing an existing record): // Filter from passed in parameter bsMTask.Filter = "pkMTaskID = " + pkMTaskID; // Populate form taMTask.Fill(dataSetHipAdmin.MTask); When I create a new row I do this: // Clear the current record this.bsMTask.AddNew(); When I delelete the current record I do this: // Apply pending changes to the underlying data source this.bsMTask.RemoveAt(0); // Send changes back to the database this.taMTask.Update(dataSetHipAdmin.MTask); When I save an edited record (or new one) I do this: // Apply pending changes to the underlying data source bsMTask.EndEdit(); // Send changes back to the database taMTask.Update(dataSetHipAdmin.MTask); ========================== ....and in the parent form - where my dataGridView is, and from where I call the child form, I approach it this way... To populate the dataGridView I do this: // Load data grid view taVwMTask_PhaseDimUnit2.Fill(dataSetHipAdmin2.vwMTask_PhaseDimUnit2); To open the child from (the editing dialog) I do this (simplified): (Note there are overridden calls to the child form depending on the presence of a record in the dataGridVView) private void btnAddViewEditTasks_Click(object sender, EventArgs e) { if (bsVwMTask_PhaseDimUnit2.Count >= 1) { // Open for editing a selected record AddEditMasterTask f = new AddEditMasterTask(pkMTaskIdDgvMTasksCurrentRow()); // Open dialog f.ShowDialog(); // Populate the TableAdapter's data table with the results of the TableAdapter's SELECT command taVwMTask_PhaseDimUnit2.Fill(dataSetHipAdmin2.vwMTask_PhaseDimUnit2); } else { // open for adding a new record when none are present AddEditMasterTask f = new AddEditMasterTask(); // Open dialog f.ShowDialog(); // Populate the TableAdapter's data table with the results of the TableAdapter's SELECT command taVwMTask_PhaseDimUnit2.Fill(dataSetHipAdmin2.vwMTask_PhaseDimUnit2); } } =========================== For your reference here are portions of my designer generated code for the child form (selected statements to show some references to bsMTask ) private void InitializeComponent() { ... this.bsMTask = new System.Windows.Forms.BindingSource(this.components); ... ((System.ComponentModel.ISupportInitialize)(this.bsMTask)).BeginInit(); ... // // bsMTask // this.bsMTask.DataMember = "MTask"; this.bsMTask.DataSource = this.dataSetHipAdmin; // // pkMTaskIDTextBox // this.pkMTaskIDTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsMTask, "pkMTaskID", true)); this.pkMTaskIDTextBox.Location = new System.Drawing.Point(129, 42); this.pkMTaskIDTextBox.Name = "pkMTaskIDTextBox"; this.pkMTaskIDTextBox.Size = new System.Drawing.Size(200, 20); this.pkMTaskIDTextBox.TabIndex = 3; this.pkMTaskIDTextBox.Visible = false; ... ((System.ComponentModel.ISupportInitialize)(this.bsMTask)).EndInit(); ... private System.Windows.Forms.BindingSource bsMTask; =========================== So with my approach using // Force the displayed the child combobox value to be pushed back to the data source this.fkMeasureDimIDComboBox.DataBindings["SelectedValue"].WriteValue(); // Apply pending changes to the underlying data source bsMTask.EndEdit(); I still get the "System.Data.NoNullAllowedException was unhandled" error. on the statement "bsMTask.EndEdit();" What am I doing wrong? How can I correct it within my situation? Thank you, Douglas |
|
||
|
||||
|
Linda Liu[MSFT]
Guest
Posts: n/a
|
Hi Douglas,
In the Form2 within my sample project, I create a BindingSource instance to bind to the dataset and datatable, and then bind the TextBox and two ComboBoxes to the BindingSource instance instead of the dataset. In the Button1's Click event handler, I call the BindingSource.EndEdit method to apply the pending changes to the underlying data source and all works well. The following is the modified code in the Form2: public partial class Form2 : Form { public Form2() { InitializeComponent(); } private DataSet ds; public DataSet DS { get { return ds; } set { ds = value; } } // create a BindingSource instance private BindingSource bs; private void Form2_Load(object sender, EventArgs e) { BindingSource bsParent = new BindingSource(ds,"Measure"); BindingSource bsChild =new BindingSource(bsParent,"Measure_Unit"); this.comboBox1.DataSource = bsParent; this.comboBox1.DisplayMember ="Name"; this.comboBox1.ValueMember = "ID"; this.comboBox2.DataSource = bsChild; this.comboBox2.DisplayMember = "Name"; this.comboBox2.ValueMember = "ID"; // bind the BindingSource instance to the dataset bs = new BindingSource(ds, "DataTable1"); // bind the controls to the BindingSource instead of the dataset this.textBox1.DataBindings.Add("Text", bs, "ID"); this.comboBox1.DataBindings.Add("SelectedValue", bs, "MeasureID"); this.comboBox2.DataBindings.Add("SelectedValue", bs, "UnitID"); // call the BindingSource.AddNew method to add a new row bs.AddNew(); } private void button1_Click(object sender, EventArgs e) { this.comboBox2.DataBindings["SelectedValue"].WriteValue(); // call the BindingSource.EndEdit method to apply the pending changes to the underlying data source bs.EndEdit(); this.Close(); } } Since I couldn't reproduce the problem in my sample project, I strongly recommend you to send me a sample project that could just reproduce the problem or modify my sample project to reproduce the problem. Thank you for your understanding and I look forward to your reply! Sincerely, Linda Liu Microsoft Online Community Support |
|
||
|
||||
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| TextBox bound to a numeric value does not allow nulls | Emil | Microsoft ADO .NET | 2 | 19th Dec 2007 04:37 PM |
| Error "object reference not set to instance of an object" when trying to set datasource property of a bound column in datagrid control | Martin Widmer | Microsoft VB .NET | 0 | 23rd Jan 2006 10:24 AM |
| How do I add a column of buttons to a bound DataGrid control? | acool | Microsoft VB .NET | 5 | 19th Jul 2004 10:39 AM |
| How do I add a column of buttons to a bound DataGrid control? | acool | Microsoft Dot NET Framework Forms | 5 | 19th Jul 2004 10:39 AM |
| How does one control the what is entered in a bound DataGrid control? | acool | Microsoft VB .NET | 1 | 22nd Apr 2004 11:11 PM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




