Reputation: 163
I choose an item out of a combo box, then enter the quantity and the price and then i click add, from there it gets put into the datagrid.
When i select that item and click the edit button, i want the data from that cell to show in the text boxs on the edit form that appears.
Upvotes: 1
Views: 905
Reputation: 1222
You can also use static variable... when you get that id
or item name (click item and edit) use any disable txtItem.text
txtItem.text = Datagridview1.databindings.Add("text",Datagridview1.Datasource,"Product");
this txtItem have now your Id or itemName. And the "Product" is the name of your datagridview1 field.
Now you code for static member
public static String str=txtItem.text;
on the next form where you want to use this use that simple code...
string val = form1.str;
and pass the value of val
to combobox.
it is the method to pass the value from one form to another by static variable.
Upvotes: 0
Reputation: 194
Send thou constructor of subForm
int id
then select from database where id = passed id.
Upvotes: 0
Reputation: 388
You can use
DataGridView.SelectedRows[0].Cells
then for each cell get the Value and then fill it into your edit-form. You can pass it by the constructor of your editform:
public class EditForm : Form
{
public EditForm(string ProductName, string Quantity, string Price, string Total)
{
/*set values to your controls/any vars*/
}
}
(At the Combobox add your ProductName list as DataSource then select the item with the value of the cell)
Hope i could help.
EDIT this only gives you the fist selected cell, so if you multiselect the others are ignored. Also don't forget to check if something is selected otherwise you get a nice NullReferenceException ;)
Upvotes: 1