110,565
社区成员
发帖
与我相关
我的任务
分享
SystemManagerProfileListDAL systemManagerProfileListDAL = new SystemManagerProfileListDAL();
DataTable table = systemManagerProfileListDAL.ListAllData(); //从数据库中取出所有数据
//为GridControl绑定数据
grcShapeProfile.DataSource = table; //GridControl数据源绑定Table
CommonClass.CommonHelper.MatchColumn(table, grvMain);
private void grvMain_DoubleClick(object sender, EventArgs e)
{
FormShapeProfileModifyAdd formShapeProfileModifyAdd = new FormShapeProfileModifyAdd();
DataRow selectRow = grvMain.GetDataRow(grvMain.FocusedRowHandle); //获取GridCotnrol MainView选中行的数据
ID = (Guid)selectRow[0]; //GUID
ItemNo = Convert.ToInt32(selectRow[1]); //序号
SysMaProList = (string)selectRow[2]; //型材类别(国标/欧标)
SysMaProListName = (string)selectRow[3];//型材名称
SysMaProListProfile = (string)selectRow[4]; // 型材规格
SysMaProListUnitWeight = Convert.ToDouble(selectRow[5]); //单位重量Kg/m
SysMaProListUnitArea = Convert.ToDouble(selectRow[6]); //单位表面积m²/m
SysMaProListRefStandard = (string)selectRow[7]; //参考标准
SysMaProListRemark = (string)CommonClass.CommonHelper.FromDbValue(selectRow[8]); //备注
formShapeProfileModifyAdd.Text = "修改"; //窗体标题赋值
formShapeProfileModifyAdd.Show(); //显示窗体
}
public void UpdateShowData(SystemManagerProfileList systemManagerProfileList)
{
SystemManagerProfileListDAL systemManagerProfileListDAL = new SystemManagerProfileListDAL();
systemManagerProfileListDAL.Update(systemManagerProfileList); //更新数据库中的数据
DataTable table = systemManagerProfileListDAL.ListAllData(); //从数据库中取出所有数据
//为GridControl绑定数据
grcShapeProfile.DataSource = table; //GridControl数据源绑定Table
CommonClass.CommonHelper.MatchColumn(table, grvMain);
}
public void 修改DataGridView行数据(dataClass data)
{
//根据传入进来的data中的id在DataGridView的数据源中进行修改,完成后重新绑定。
//如果你原先DataGridView的被修改后处于选中状态,希望更新后还保持原来的状态,可以遍历一下所有行,按条件重新设定DataGridView的FirstDisplayedScrollingRowIndex,这样就处于被选中状态了。
}
接着在你的Form2中,在修改数据的btnSave_Click事件里面,在修改完成后执行一下这样一个方法:
if (this.Owner is Form1) ((Form1)this.Owner).修改DataGridView行数据(data);
这样就行了,当然你通过委托来写也是可以的。
private void btnSave_Click(object sender, EventArgs e)
{
if (this.Text == "修改")
{
SystemManagerProfileList systemManagerProfileList = new SystemManagerProfileList();
SystemManagerProfileListDAL systemManagerProfileListDAL = new SystemManagerProfileListDAL();
systemManagerProfileList.ID = FormShapeProfile.ID;
systemManagerProfileList.ItemNo = Convert.ToInt32(txtShapeItem.Text);
systemManagerProfileList.SysMaProList = cmbShapeType.Text;
systemManagerProfileList.SysMaProListName = cmbShapeName.Text;
systemManagerProfileList.SysMaProListProfile = txtShapeProfile.Text;
systemManagerProfileList.SysMaProListUnitWeight = Convert.ToDouble(txtWeightPerUnit.Text);
systemManagerProfileList.SysMaProListUnitArea = Convert.ToDouble(txtAreaPerUnit.Text);
systemManagerProfileList.SysMaProListRefStandard = cmbRefStandard.Text;
systemManagerProfileList.SysMaProListRemark = txtShapeRemark.Text;
systemManagerProfileListDAL.Update(systemManagerProfileList); //更新数据库中的数据
//下面代码不起作用,该如何写?
DataTable table = systemManagerProfileListDAL.ListAllData(); //从数据库中取出所有数据
//为GridControl绑定数据
FormShapeProfile formShapeProfile = new FormShapeProfile();
GridControl grcShapeProfile = new GridControl();
grcShapeProfile = (GridControl)formShapeProfile.Controls["grcShapeProfile"];
grcShapeProfile.DataSource = table; //GridControl数据源绑定Table
CommonClass.CommonHelper.MatchColumn(table, (GridView)grcShapeProfile.MainView);
}