我每次编辑单元格时都需要刷新DataGridView
。它位于CellEndEdit
事件中:
private void gridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
//some code for updating to database here
Grid_Load();
}
Grid_Load(code)
具有正常的刷新任务:
public void Grid_Load(string code)
{
try
{
String sqlString = "SELECT e.room, e.room, c.code, c.[weight], c.[date], c.sender, c.receiver, c.container, c.seal, c.note " +
"FROM loadingPlan a INNER JOIN loadingPlanDetail b " +
"ON a.ID = b.loadingID INNER JOIN containerTransaction c " +
"ON b.transactionCode = c.code LEFT JOIN stowage d " +
"ON a.code = d.loadingCode LEFT JOIN stowageDetail e " +
"ON b.transactionCode = e.transactionCode " +
"WHERE a.code = @code " +
"AND d.ID = @id " +
"ORDER BY c.[weight] ASC ";
using (SqlDataAdapter da = new SqlDataAdapter(sqlString, connString))
{
da.SelectCommand.Parameters.Add("@code", SqlDbType.VarChar).Value = code;
da.SelectCommand.Parameters.Add("@id", SqlDbType.VarChar).Value = this.id;
using (DataSet ds = new DataSet())
{
da.Fill(ds, "data");
DataTable dt = new DataTable();
dt = ds.Tables["data"];
gridView.DataSource = dt;
gridView.Columns[0].ReadOnly = true;
gridView.Columns[0].Visible = false;
gridView.Columns[1].HeaderText = "Room";
gridView.Columns["code"].HeaderText = "No. Transaksi";
gridView.Columns["code"].ReadOnly = true;
gridView.Columns["weight"].HeaderText = "Berat";
gridView.Columns["weight"].ReadOnly = true;
gridView.Columns["date"].HeaderText = "Tanggal";
gridView.Columns["date"].ReadOnly = true;
gridView.Columns["sender"].HeaderText = "Pengirim";
gridView.Columns["sender"].ReadOnly = true;
gridView.Columns["receiver"].HeaderText = "Penerima";
gridView.Columns["receiver"].ReadOnly = true;
gridView.Columns["container"].HeaderText = "No. Kontainer";
gridView.Columns["container"].ReadOnly = true;
gridView.Columns["seal"].HeaderText = "No. Seal";
gridView.Columns["seal"].ReadOnly = true;
gridView.Columns["note"].HeaderText = "Keterangan";
gridView.Columns["note"].ReadOnly = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
当我在编辑单元格时单击另一个单元格时,一切都很完美,但有些奇怪的异常。
操作无效,因为它会导致重新调用 SetCurentCellAddressCore函数
在编辑时单击时抛出此错误。 Arrow,Enter完美无缺。