I have a large dataset that load in with a fill method on page load.
Then, a record can be added to the dataset.
All of that works fine, but the only way that I can get the bindingsource to recognize the new record is to do a fill method. This also works but is a perfomance problem. Why does the binding source not see the new record in the dataset?
Mainform Code. Works Great.
DialogResult returnFormVal;
Schedulers.DataSets.SchedOneFetch.WOMainFetchRow newRow = schedOneFetch.WOMainFetch.NewWOMainFetchRow();
Schedulers.Forms.NewWorkOrder genReport = new Schedulers.Forms.NewWorkOrder(ref newRow);
Int32 picNumber;
returnFormVal = genReport.ShowDialog();
schedOneFetch.WOMainFetch.Rows.Add(newRow);
wOMainFetchBindingSource.EndEdit();
wOMainFetchTableAdapter.Adapter.Update(schedOneFetch.WOMainFetch);
Int32 passBackVal = newRow.DISID;
SubForm code. Also works great.
passBackRow.DISDueDate = monthCalendar1.SelectionStart;
passBackRow.DISID = 99999999;
if (ckbEqpt.Checked == true & lbProcNum.Items.Count > 0)
{
passBackRow.DISEquip = Convert.ToInt32(lbProcNum.SelectedValue.ToString());
}
else
{
passBackRow.DISEquip = 0;
}
passBackRow.DISLineNumber = Convert.ToInt32(lbLineName.SelectedValue.ToString());
passBackRow.DISManHours = Convert.ToInt32(nudEstTotTime.Value);
passBackRow.DISNumberAss = Convert.ToInt32(nudEstTM.Value);
passBackRow.DISOpenDate = DateTime.Now;
passBackRow.DISOriginator = userID.DBUserID;
passBackRow.DISRequestor = 0;
passBackRow.DISResponsible = Convert.ToInt32(lbRespons.SelectedValue.ToString());
passBackRow.DISType = Convert.ToInt32(lbType.SelectedValue.ToString());
passBackRow.DISWorkAccomp = "";
passBackRow.DISWorkRequired = rtbWorkReq.Text;
passBackRow.MLID = 0;
passBackRow.LIID = 0;
passBackVal = 0;
this.Close();
Return control to main form. The new record has been added to the database.
wOMainFetchBindingSource.Position = wOMainFetchBindingSource.Find("DISID", passBackVal);
DataRowView dtaRow = (DataRowView)wOMainFetchBindingSource.Current;
String woID = dtaRow["DISID"].ToString();
FAIL! The bindingsource wont find the the new record, returns a -1 on the find and defaults to the first record in the dataset.
If I put the .fill method in between the dialog and the main page then it all works fine, but takes a loooonnng time to do the fill... seven or eight seconds.
I guess my understanding of the binding source is disfunctional, I had assumed that if the underlying dataset was updated then the bindingsource would see it.
So, first if someone has a suggestion on how to refresh the binding source without the fill I would appreciate it, and if someone can explain why this works the way it does I might be able to find a workaround.
Thanks
My understanding of the Bindingsource was correct, it was seeing the new record added. The issue is that the Dataset gets its information from a view. The add new method only populates the fields in the base table. The other fields, the ones assembled by the View, arent populated until the tableadapter re-reads by using the fill method. I dont see a way around this other than filling each of the fields of the new record, big drawback is that whenever the view or any of the tables assembled in the view are changed you would have to make sure to change the code. I will instead reduce the number of records being loaded on each fill.