I have a datagridview
with datagridviewbuttoncolumn
, I used the button to show search form for select data from another table. when user select data from search form I want to update current datagridviewrow
with selected data:
when user select search button for first time datagridview
row update correctly and a new row add at the end of rows:
but when select search button for second time the new row at the end do not appears.
How can I fix this problem? is there better solution to do this?
private void dgvPlannedWoInstruction_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var senderId = (DataGridView) sender;
if (senderId.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
{
var frmSearch = new FrmStandardInstructionList();
frmSearch.ShowDialog();
if (frmSearch.ucStandardInstructionList1.standardInstructionDto != null)
{
senderId.BeginEdit(true);
PlannedInstructionDTO p;
senderId.NotifyCurrentCellDirty(true);
senderId.BeginEdit(true);
senderId.CurrentRow.Cells["StandardInstructionCode"].Value = frmSearch.ucStandardInstructionList1.standardInstructionDto.Number;
senderId.CurrentRow.Cells["StandardInstructionId"].Value = frmSearch.ucStandardInstructionList1.standardInstructionDto.Id;
senderId.EndEdit();
}
}
}
You could refresh the DataSource after it has been updated like:
DataGridView view = new DataGridView();
view.DataSource = somesource;
view.DataSource = null;
view.DataSource = updatedsource;
Sorry I can't post comments, but this should help. See also: How can I refresh c# dataGridView after update ?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.