General information
Category:
The Mere Mortals .NET Framework
Title:
Create a New Row in the DataDridView
Kelvin,
I am having problem getting the new row added to show up on the datagridview. If after creating a new record and type in all neccessary information of the new row, I do not have any problem saving.
I have a business object "Purchase" and a child business object "Purchase Detail". Using the maintenance form to create Master/Child form to maintain the information. For the "PurchaseDetail", I used a mmPicker to retrieve the "Product" from the the pick list to be inserted as a "PurchaseDetail" item. The Primary key for "Purchase" is "PurchaseID" and the for "PurchaseDetail" is "PurchaseID, ProductID". The DataGridView is bound to the "PurchaseDetail" object.
Here is the event callback for ItemSelected:
private void pckProductSearch_ItemSelected(object sender, mmPickerItemSelectedEventArgs e)
{
DataRow aNewRow = this.oPurchaseDetail.NewRow();
aNewRow[this.oPurchaseDetail.PrimaryKeys[0]] = this.oPurchase.Entity.PurchaseID;
aNewRow[this.oPurchaseDetail.PrimaryKeys[1]] = e.dsSelectedItems.Tables[0].Rows[0][this.oProduct.PrimaryKey];
this.grdPurchaseDetail.NavigateData(mmNavigate.Last);
this.grdPurchaseDetail.Focus();
}
The code assign the primary keys to the "PurchaseDetail" from "PurchaseID" from the "Purchase" object and "ProductID" from the selection of the picklist. All other columns in the new record is nullable and does not require any data.
After this method is called, I expected to see the new row appear in the datagridview, but I only see a blank row. Am I missing something here? Why does the DataGridView get updated to the dataset that it is bounded to.
Thanks and Have a Nice Day,
Peter Nguyen
Next
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