使用form2中的更改更新form1中的datagridview [英] updating the datagridview in form1 with changes in form2
问题描述
我已经做了一个单一格式的datagridview行单元格,形式1另一种形式,表格2将与form1上选定的数据网格视图数据一起打开。
我正在使用winforms ... c#
我已经对datagrid视图数据做了一些操作,在操作阶段结束时,form2将被关闭
注意:我已经完成
我想更新form1中的datagridview,我已经在form2中完成了更改,因为我已经这样做了。
形式1:
private void productGridview_Cellclick(object sender,DataGridViewCellEventArgs e)
{
if(e.ColumnIndex!= productgridview.Columns [productimage]。
if(productgridview.SelectedCells.Count == 0)return;
int selectedrowindex = productgridview.SelectedCells [0] .RowIndex;
DataGridViewRow selectedRow = productgridview.Rows [selectedrowindex];
if(img is Image)
{
using(ProductDescriptionForm pf = new ProductDescriptionForm())
{
pf.picture = img;
pf.productname = productname;
pf.description = desc;
pf.productprice = productprices;
pf.categoryname = categoryCombobox.Text;
pf.productid = productids;
pf.ShowDialog(this);
}
}
}
在form2中:这样做...
public int productid
{
get {return _prodid; }
set {_prodid = value; }
}
public Image picture
{
get {return pictureBox1.Image; }
set {pictureBox1.Image = value;
}
像我这样使用的一些构造函数,然后
在datagridview中删除一行,使用下面的代码...它的罚款..
private void btnProdDelete_Click(object sender,EventArgs e)
{
using(var context = new TsgEclipseEntities())
{
var pd = new product(){product_Id = productid};
context.products.Attach(pd);
context.DeleteObject(pd);
context.SaveChanges();
this.Close(); // form2 close
}
}
现在我想更新form1中的datagridview我该怎么做.....
可以有任何人有这个想法...
非常感谢....
1)写一个接受product_id参数的数据绑定方法获取数据格式1
2)在form2.close之前,初始化form 1类,并通过传递刚刚更新的product_id并打开form1来调用该方法。
I have done for clicking one the datagridview row cell in one form say form 1 another form say form 2 will open along with selected data grid view data on form1..
I am using winforms...c#
i have done some operations on datagrid view data and at the end of the operations stage the form2 will be closed
NOTE :upto this i have finished
i want to update the datagridview in form1 with changes i have done in form2
for that i have done like this..
form 1:
private void productGridview_Cellclick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex != productgridview.Columns["productimage"].Index) return;
if (productgridview.SelectedCells.Count == 0) return;
int selectedrowindex= productgridview.SelectedCells[0].RowIndex;
DataGridViewRow selectedRow = productgridview.Rows[selectedrowindex];
if (img is Image)
{
using (ProductDescriptionForm pf = new ProductDescriptionForm())
{
pf.picture = img;
pf.productname = productname;
pf.description = desc;
pf.productprice = productprices;
pf.categoryname = categoryCombobox.Text;
pf.productid = productids;
pf.ShowDialog(this);
}
}
}
and in form2 : I have done like this ...
public int productid
{
get { return _prodid; }
set { _prodid = value; }
}
public Image picture
{
get { return pictureBox1.Image; }
set { pictureBox1.Image = value; }
}
like this some constructors i have used and then
i have deleted one row in datagridview by using below code ...its fine..
private void btnProdDelete_Click(object sender, EventArgs e)
{
using(var context = new TsgEclipseEntities())
{
var pd = new product(){ product_Id = productid };
context.products.Attach(pd);
context.DeleteObject(pd);
context.SaveChanges();
this.Close(); // form2 close
}
}
now i want to update the datagridview in form1 how i have to do that .....
can any one have idea about this ...
many thanks....
1) write a databind method that accepts a product_id parameter to get data in form 1
2) Before form2.close, intialize form 1 class, and call the method by passing the product_id you just updated and open form1.
这篇关于使用form2中的更改更新form1中的datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!