Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > (Should be a simple) BindingSource question
 

(Should be a simple) BindingSource question

Ok. I was under the impression that when you databound a control to a BindingSource, the BindingSource should handle the updating of the DataSet.

I have a TextBox bound to anullabledateTime field in a BindingSource. If I make any changes to the date it updates the DataSet and database just fine. But if I DELETE the date in the TextBox, I get no error but the DataSet never shows pending changes. I am also manually calling EndEdit() on the BindingSource.

So what gives? HOW do I propagate this deletion to the BindingSource then the DataSet as a change? I am getting down into the real nuts and bolts of the BindingSource, converting out the DataRowView and trying to remove the data in there, but there MUST be an easier way.

Thanks

Kurt

Kurt Wimberger  Wednesday, June 11, 2008 8:02 PM

Ok, I think I finally figured this one out. It seems that if you use one of the overloaded methods of creating a binding that allows for you to choose a default value for any null data...

this.txtDepartureDate.DataBindings.Add(

new System.Windows.Forms.Binding(

"Text", this.tblTripBindingSource, "DepartureDate", true,

System.Windows.Forms.DataSourceUpdateMode.OnValidation, string.Empty));

... then the binding will handle the conversion for you. BUT - and there's always a but - the examples tend to show null as the value to choose when it is actually string.Empty!

This one took *way* too long to solve. I have been at it since 4:00 pm MST yesterday. I am stunned that there seems to be so little documentation on this.

Hope this helps someone else.

Kut

Kurt Wimberger  Wednesday, June 11, 2008 8:39 PM

Ok, I think I finally figured this one out. It seems that if you use one of the overloaded methods of creating a binding that allows for you to choose a default value for any null data...

this.txtDepartureDate.DataBindings.Add(

new System.Windows.Forms.Binding(

"Text", this.tblTripBindingSource, "DepartureDate", true,

System.Windows.Forms.DataSourceUpdateMode.OnValidation, string.Empty));

... then the binding will handle the conversion for you. BUT - and there's always a but - the examples tend to show null as the value to choose when it is actually string.Empty!

This one took *way* too long to solve. I have been at it since 4:00 pm MST yesterday. I am stunned that there seems to be so little documentation on this.

Hope this helps someone else.

Kut

Kurt Wimberger  Wednesday, June 11, 2008 8:39 PM

You can use google to search for other answers

Custom Search

More Threads

• link on datagridview
• Problem with data from a CSV file
• Setting Cell Forecolor gotcha
• ContextMenuStrip in DataGridView - get the current column
• DataView instance problem!
• Determine mouse XY coordinates for double-click
• Trying to upload an XML file into Text box and DataGridview
• Activate/deactivate and format cells in a datagridview using a checkbox column
• DataGridView with paging, custom sorting and ...
• GridView Question