General information
Category:
The Mere Mortals .NET Framework
Hi Mike,
I have encountered similar problems using a grid setup as described in the jump start example. In this example a call is made to save the row to the database when the UPDATE button is clicked. When a new parent record is added but not yet saved, attempting to save child rows would cause constraint issues. Kevin suggested that I do the following. Mind you this was in response to a slightly different question but this should still apply.
When you get to the section where it shows code for the grdCategories_UpdateCommand handler method, rather than calling:
this.oCategory.SaveDataSet(dsCategories);
You can call the DataGrid's BindBack method instead, passing the DataSet and TableName.
Give this a try.
Regards,
Terry Carroll
>I've got a nearly classic situation I stole right from the jumpstart where there is a child grid on the properties page of an mmMaintenanceForm. I placed a mmButtonNew on the form and set the BindingSource property. I then needed to pre-populate a couple of the columns with data specific to this form. I think the way I did it is pretty ugly, but it looks like this:
>
>//Set defaults for new DataRow
>dsDrugDose = oDrugDose.GetCurrentDataSet();
>int rowNum = dsDrugDose.Tables["lkup_drug_dose"].Rows.Count - 1;
>DataRow myRow = dsDrugDose.Tables["lkup_drug_dose"].Rows[rowNum];
>myRow["Dose"] = "";
>myRow["Default_Dose"] = 0;
>
>this.grdForms.NavigateData(mmNavigate.Last);
>this.grdForms.Focus();
>
>Everything works except that when I add a new parent record, then add new child records without first saving the parent, I get constraint violations in the database. Is there a way I can force the parent record to be written to the db first? Adding new child records to an existing parent works great.
>
>Also, if there is something a little more elegant for setting default values for columns in the new row, I'd love to use it!
>
>Thanks in advance,
>Mike
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only