Pass data from a selected row in a DG to a new form  
Author Message
BMackKC





PostPosted: Visual Basic General, Pass data from a selected row in a DG to a new form Top

Hello all.

I have a datagrid in my form which displays basic information about open purchase orders. When I select a row in that grid, I want to pass the data in that row (actually only the SQL record ID) to a new form, which on load will fire a stored procedure that will populate the the new form fields.

I can't figure out how to pass the cell value of the selected row to the new form.

Any help would be appreciated.

Mike



Visual Basic20  
 
 
Zaben





PostPosted: Visual Basic General, Pass data from a selected row in a DG to a new form Top

First we will get the current row then we get Id from its column then pass it to the second form -- sorry the code C# but it may help you


private void btnPurchase_Click(object sender, EventArgs e)
{

DataRowView rowView = this.purchaseBindingSource.Current;
if (rowView == null)
{

MessageBox.Show("Please choose another item");
return;

}

int id = (int)rowView.Row["PurchaseID"];
ItemForm frmItem = ItemForm();
frmItem.PurchaseID = id;
frmItem.ShowDialog();

}

In the second form add a property

private int m_purchaseId;
public int PurchaseID
{

get
{

return m_purchaseId;

}
set
{

m_purchaseId = value;

}

}

 Now you can pass it to your stored procedure

Zaben