private void btnUpdate_Click(object sender, EventArgs e) { if (!CheckSelectedRow()) { return; } if (!CheckData()) { return; } if (!UpdateBasicGoodsInfo()) { return; } S_Stock stockInfo = CreateStockObject(); stockInfo.ID = (int)dataGridView1.CurrentRow.Cells[0].Value; if (stockInfo.GoodsCode != dataGridView1.CurrentRow.Cells["图号型号"].Value.ToString().Trim() || stockInfo.GoodsName != dataGridView1.CurrentRow.Cells["物品名称"].Value.ToString().Trim() || stockInfo.Spec != dataGridView1.CurrentRow.Cells["规格"].Value.ToString().Trim()) { MessageDialog.ShowErrorMessage("不允许修改物品的图号、名称、规格信息!"); return; } // 获取到修改行索引 int rowIndex = dataGridView1.CurrentRow.Index; if (!m_storeServer.UpdateStore(stockInfo, out m_error)) { MessageDialog.ShowErrorMessage(m_error); return; } QueryStock(); RefreshControl(); string strColName = ""; foreach (DataGridViewColumn col in dataGridView1.Columns) { if (col.Visible) { strColName = col.Name; break; } } // 自动跳到下一行记录 if (rowIndex != dataGridView1.Rows.Count - 1) { dataGridView1.CurrentCell = dataGridView1.Rows[rowIndex + 1].Cells[strColName]; } dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex; dataGridView1.Focus(); chk_PT.Enabled = false; }