// FormMain
FormEntry frmEntry = new FormEntry();
//dgEntry - datagrid
//parameter - row in DataView vueInvoice which i want edit
frmEntry.Show(vueInvoice[dgEntry.CurrentRowIndex]);
frmEntry.Dispose();
//FormEntry
public void Show(DataRowView Invoice)
{
drvInvoice = Invoice;
drInvoice = (DataSetIndustry.InvoiceRow) drvInvoice.Row;
dsIndustry = (DataSetIndustry)drInvoice.Table.DataSet;
if (this.ShowDialog() == DialogResult.OK)
{
if (drInvoice.RowState != DataRowState.Detached)
drvInvoice.BeginEdit();
drvInvoice["InvoiceID"] = Convert.ToInt32(txtInvoice.Text);
drvInvoice["Date"] = Convert.ToDateTime(txtDate.Text);
drvInvoice["SupplierID"] = (int)cbSupplier.SelectedValue;
drvInvoice["DPH"] = (byte) cbDPH.SelectedValue;
drvInvoice.EndEdit();
}
else
{
if (drInvoice.RowState == DataRowState.Detached)
drvInvoice.CancelEdit();
}
}
//add new supply
DataRowView drvNewSupply = vueSupply.AddNew();
FormSupply frmSupply = new FormSupply();
if (drInvoice.RowState == DataRowState.Detached)
{
//set InvoiceID - relation
drvInvoice["InvoiceID"] = Convert.ToInt32(txtInvoice.Text);
drvInvoice.EndEdit();
}
frmSupply.iInvoiceID = drInvoice.InvoiceID;
frmSupply.Show(drvNewSupply);
frmSupply.Dispose();
//FormSupply
public void Show(DataRowView Supply)
{
DataRowView drvSupply = Supply;
drSupply = (DataSetIndustry.SupplyRow) drvSupply.Row;
dsIndustry = (DataSetIndustry) drSupply.Table.DataSet;
if (this.ShowDialog() == DialogResult.OK)
{
if(drSupply.RowState != DataRowState.Detached)
drvSupply.BeginEdit();
else
drSupply.InvoiceID = iInvoiceID;
drvSupply["Class"] = (string) cbClass.SelectedValue;
drvSupply["Gross"]= (byte) cbGross.SelectedValue;
drvSupply.EndEdit();
}
else
{
if (drSupply.RowState == DataRowState.Detached)
drvSupply.CancelEdit();
}
}