Microsoft Windows Forms Data Binding
Windows Databinding Resources
Article by Noah Coad, a C# MVP which points out that calling AddNew() on a BindingSource results in a detached DataRow, when binding to a DataSet, until the BindingSource position is changed. See the code fragment below which shows how one might pass a BindingSource and a bool flag to tell a form to either create a new row in the BindingSource's DataSource (which is a DataSet), or just edit an existing row. For the latter, the trick is to make sure that the BindingSource's Position is set to the row that you want to edit. (Hint: use BindingSource.Position = BindingSource.Find(...))
public Form1(BindingSource bs, bool isAddNew)
{
InitializeComponent();
this.bindingSource = bs;
if(isAddNew)
{
DataRowView drv = this.bindingSource.AddNew() as DataRowView;
cemOrderDataSet.cemOrderRow row = drv.Row as cemOrderDataSet.cemOrderRow;
row.orderId = eventCounter;
row.productId = 0;
this.bindingSource.Position = this.bindingSource.IndexOf(drv);
}
}
Microsoft's Roadmap for Windows Forms data binding contains info and lots of links.
DataBinding FAQ (Microsoft Word Format)
Dealing with Nulls
Microsoft's comments on the issue of the !DataSet designer's poor support for Nulls. See the embedded link for work arounds.
Same solution via a knowledge base article.
One (Microsoft) work around for dealing with nulls in the DataSet Designer
More of the same from a book excerpt - might be a good book to pick up.
Another non-MS solution for Working will Nullable column values in the DataSet Designer
The google search which yielded a lot of this stuff.
DataSet Tweaking
Gotchs
DataSets generated from web service reference has surprise
Datasets that contains datatables that contain datacolumns that can be null will by default throw an exception when you try to access that column value. There are a couple of different ways to deal with it. One of things that you can do is change the dataset's default behavhior from throwing an exception to returning some default value. For columns that are strings you can for example set the "NullValue" property of the data column to and empty string "". An IMPORTANT NOTE is that this does not work DataSet objects that are reference via a generated Web Service proxy. There is a bug in the code generation that does not pick up on the fact that the code should return the empty string and you end up with an exception after all. See this newsgroup thread.