我有两个窗体AddProduct和updateproduct
AddProduct窗体中有两个datagridview1和datagridview2 和一个添加按钮
我想在AddProduct窗体中单击一次按钮就弹出updateproduct窗体这个updateproduct获得AddProduct中datagridview1的值和一些其他的值
我用了一个类( ProductInfo)来传到updateproduct中
当updateproduct关闭时AddProduct的datagridview2 添加一条数据
但我的AddProduct窗体添加数据时只能添加一次,datagridview2 中只能显示一次在不知道为什么!public List<ProductInfo> myproducts = new List<ProductInfo>();
AddProduct添加事件中代码
{
ProductInfo myproduct = new ProductInfo();
updateproduct myupdate = new updateproduct(myproduct);
myupdate.ShowDialog();
myproducts.Add(myproduct);
this.dataGridView3.DataSource = mycollection.myproducts;
} ProductInfo myproduct;
public updateproduct(ProductInfo product)
{
InitializeComponent();
myproduct = product;
}
private void button1_Click(object sender, EventArgs e)--updateproduct窗体确定事件
{
if (txtgoodsprice.Text == "")
MessageBox.Show("进货价格不能为空!");
if (txtgoodsunit.Text == "")
MessageBox.Show("进货单位不能为空!");
if (txtgoodsnum.Text == "")
MessageBox.Show("进货数量不能为空!");
myproduct.Goodsbrand = txtgoodsbrand.Text;
myproduct.Goodscol = txtgoodscol.Text;
myproduct.Goodsid = txtgoodsid.Text;
myproduct.Goodsize = txtgoodsize.Text;
myproduct.Goodsname = txtproname.Text;
myproduct.Goodsnum = int.Parse( txtgoodsnum.Text);
myproduct.Goodsprice =int.Parse( txtgoodsprice.Text);
myproduct.Goodstype = txtgoodstype.Text;
myproduct.Goodsunit = txtgoodsunit.Text;
this.Close(); }
AddProduct窗体中有两个datagridview1和datagridview2 和一个添加按钮
我想在AddProduct窗体中单击一次按钮就弹出updateproduct窗体这个updateproduct获得AddProduct中datagridview1的值和一些其他的值
我用了一个类( ProductInfo)来传到updateproduct中
当updateproduct关闭时AddProduct的datagridview2 添加一条数据
但我的AddProduct窗体添加数据时只能添加一次,datagridview2 中只能显示一次在不知道为什么!public List<ProductInfo> myproducts = new List<ProductInfo>();
AddProduct添加事件中代码
{
ProductInfo myproduct = new ProductInfo();
updateproduct myupdate = new updateproduct(myproduct);
myupdate.ShowDialog();
myproducts.Add(myproduct);
this.dataGridView3.DataSource = mycollection.myproducts;
} ProductInfo myproduct;
public updateproduct(ProductInfo product)
{
InitializeComponent();
myproduct = product;
}
private void button1_Click(object sender, EventArgs e)--updateproduct窗体确定事件
{
if (txtgoodsprice.Text == "")
MessageBox.Show("进货价格不能为空!");
if (txtgoodsunit.Text == "")
MessageBox.Show("进货单位不能为空!");
if (txtgoodsnum.Text == "")
MessageBox.Show("进货数量不能为空!");
myproduct.Goodsbrand = txtgoodsbrand.Text;
myproduct.Goodscol = txtgoodscol.Text;
myproduct.Goodsid = txtgoodsid.Text;
myproduct.Goodsize = txtgoodsize.Text;
myproduct.Goodsname = txtproname.Text;
myproduct.Goodsnum = int.Parse( txtgoodsnum.Text);
myproduct.Goodsprice =int.Parse( txtgoodsprice.Text);
myproduct.Goodstype = txtgoodstype.Text;
myproduct.Goodsunit = txtgoodsunit.Text;
this.Close(); }
解决方案 »
- 学生求教:dropdownlist选择不同值时gridview绑定一个数据库里多个表的问题
- 请问,这个关于ListBox的操作,怎么写
- XML的问题
- 强制终止线程???
- C#Socket 服务器
- 續:DataGridView 綁定IList<T> 後無法編輯表格。我知道原因了,原來是Model裡的屬性我控制為隻讀的了
- 求msn客户端发信息
- 请问,如何在visio2003里的uml图里做子类继承和接口实现??
- 如何让C#控制ASP.NET页面的自定义按扭不显示
- 将元数据写入文件“ ”时发生错误--“存储空间不足,无法完成此操作”,,本人尝试了很久都没有找到合适的方法来解决
- listview控件怎么能够选中一行一行?
- C#winform 怎么设置自动竖直滚动条?
?
这里是this.dataGridView2.DataSource = mycollection.myproducts;
-----------------------------------
这是什么意思?
窗体设置完值后关闭该窗体将值添加到datagridview2中
如果在单击添加按钮就无法将从updateproduct窗体中的值添加到datagridview2中
只能添加一回
我想要在AddProduct窗体中单击添加按钮一次就在datagridview2中加一条数据
好像不能绑定吧
{
ProductInfo myproduct = new ProductInfo();
updateproduct myupdate = new updateproduct(myproduct);
myupdate.ShowDialog();
myproducts.Add(myproduct);
this.dataGridView3.DataSource = mycollection.myproducts;
}
-------------------------------
这是完整的添加按钮单击事件处理代码?
this.dataGridView3.DataSource = mycollection.myproducts;
--------------------------------------------
上面的两个myproducts是不是同一个?
这个方法是在mycollection这个类中定义的?
ProductInfo myproduct = new ProductInfo();
只要把this.dataGridView3.DataSource = mycollection.myproducts;
改成this.dataGridView3.DataSource = mycollection.myproducts.ToArray();
问题就解决了。
改成this.dataGridView2.DataSource = mycollection.myproducts.ToArray();
问题就解决了。