public void SetParentView() { try { int rowIndex = this.dataGridView1.SelectedRows[0].Index; if (this.dataGridView1.Rows[rowIndex].Cells["name"].Value != null) { string code = this.dataGridView1.Rows[rowIndex].Cells["code"].Value.ToString(); string name = this.dataGridView1.Rows[rowIndex].Cells["name"].Value.ToString(); string itemtype = this.dataGridView1.Rows[rowIndex].Cells["itemtype"].Value.ToString(); string feetype = this.dataGridView1.Rows[rowIndex].Cells["feetype"].Value.ToString(); string forms = this.dataGridView1.Rows[rowIndex].Cells["forms"].Value.ToString(); string formsName = ""; if (!String.IsNullOrEmpty(forms)) { formsName = "(" + forms + ")"; } ((DataGridView)this.Parent.Controls["ScanDataGridView"]).EndEdit(); ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["CenterCode"].Value = code; ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["CenterName"].Value = name + formsName; ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["itemtype"].Value = itemtype; ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["feetype"].Value = feetype; this.Visible = false; dataGridView1.DataSource = null; //在datagridview点击之后,把中心编码赋值到mainform的变量中,记录单元格赋值之后的值 //获取原始值 string oldName = ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["oldName"].Value.ToString(); string newName = ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["nameDataGridViewTextBoxColumn"].Value.ToString(); if (this.Parent.FindForm() is MainForm) { MainForm form = (MainForm)(this.Parent.FindForm()); form.UpdateItemDictRelation(oldName, newName, code); } if (this.Parent.FindForm() is MainInfoList) { MainInfoList form = (MainInfoList)(this.Parent.FindForm()); form.UpdateItemDictRelation(oldName, newName, code); } } } catch (Exception ex) { throw new ApplicationException("回车赋值中心项目异常:" + ex.ToString()); } }
private void dataGridView1_MouseDown(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Left && SearchType.Equals("Item")) { DataGridView.HitTestInfo hit = this.dataGridView1.HitTest(e.X, e.Y); int rowIndex = hit.RowIndex; string code = this.dataGridView1.Rows[rowIndex].Cells["code"].Value.ToString(); string name = this.dataGridView1.Rows[rowIndex].Cells["name"].Value.ToString(); string itemtype = this.dataGridView1.Rows[rowIndex].Cells["itemtype"].Value.ToString(); string feetype = this.dataGridView1.Rows[rowIndex].Cells["feetype"].Value.ToString(); string forms = this.dataGridView1.Rows[rowIndex].Cells["forms"].Value.ToString(); string formsName = ""; if (!String.IsNullOrEmpty(forms)) { formsName = "(" + forms + ")"; } ((DataGridView)this.Parent.Controls["ScanDataGridView"]).EndEdit();//只有结束编辑才能赋值 ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["CenterCode"].Value = code; ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["CenterName"].Value = name + formsName; ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["itemtype"].Value = itemtype; ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["feetype"].Value = feetype; this.Visible = false; dataGridView1.DataSource = null; //在datagridview点击之后,把中心编码赋值到mainform的变量中,记录单元格赋值之后的值 //获取原始值 string oldName = ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["oldName"].Value.ToString(); string newName = ((DataGridView)this.Parent.Controls["ScanDataGridView"]).CurrentRow.Cells["nameDataGridViewTextBoxColumn"].Value.ToString(); if (this.Parent.FindForm() is MainForm) { MainForm form = (MainForm)(this.Parent.FindForm()); form.UpdateItemDictRelation(oldName, newName, code); } if (this.Parent.FindForm() is MainInfoList) { MainInfoList form = (MainInfoList)(this.Parent.FindForm()); form.UpdateItemDictRelation(oldName, newName, code); } } } catch (Exception ex) { throw new ApplicationException("点击选择中心项目异常:" + ex.ToString()); } }