使用DataGridView和DataSource = null,如何使用以编程方式更改的单元格值重新显示网格 . 我已尝试刷新和更新,但显示不会改变...我已经验证新值是在单元格中 .
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
// The mouse locations are relative to the screen, so they must be
// converted to client coordinates.
Point myClientPoint = dataGridView1.PointToClient(new Point(e.X, e.Y));
// Get the row index of the item the mouse is over.
m_TargetHTI = dataGridView1.HitTest(myClientPoint.X, myClientPoint.Y);
DataGridViewCell myTargetCell = dataGridView1[m_TargetHTI.ColumnIndex, m_TargetHTI.RowIndex];
if (e.Effect == DragDropEffects.Move)
{
//save the source/target cell's original values
AddCellHistory(m_DragCell);
AddCellHistory(myTargetCell);
//
//move source to target
dataGridView1.Rows[m_TargetHTI.ColumnIndex].Cells[m_TargetHTI.RowIndex].Value = m_DragCell.Value;
//
//clear source cell
dataGridView1.Rows[m_SourceHTI.ColumnIndex].Cells[m_SourceHTI.RowIndex].Value = null;
}
}
1 回答
您应该在datagrid上调用Invalidate方法,如下所示: