【发布时间】:2011-08-19 16:04:52
【问题描述】:
我已经完成了单击一个表单中的 datagridview 行单元格的操作,比如说表单 1,另一个表单说表单 2 将与表单 1 上选定的数据网格视图数据一起打开。
我正在使用 winforms...c#
我已经对datagrid视图数据做了一些操作,在操作阶段结束时form2将被关闭
NOTE :upto this i have finished
我想用我在 form2 中所做的更改来更新 form1 中的 datagridview
为此我已经这样做了..
表格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);
}
}
}
在form2中:我已经这样做了......
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
我已经使用下面的代码删除了 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 我该怎么做.....
任何人都可以对此有所了解...
非常感谢....
【问题讨论】:
-
你的数据源 MS-SQL 是什么?
-
不,我的数据库是 mysql,我正在使用 mysql 工作台检索数据,然后我将数据连接到 model.edmx
标签: c# .net winforms data-binding datagridview