2015-10-12 18 views
0

我有一個datagridviewdatagridviewbuttoncolumn,我用按鈕來顯示從另一個表中選擇數據的搜索表單。當從搜索表單用戶選擇的數據我想選擇的數據來更新當前datagridviewrowenter image description here當datagridview結束時添加行綁定到列出新行添加行後不顯示

當第一次用戶選擇搜索按鈕datagridview行更新正確和新行添加在行的末尾:

enter image description here

但是當第二次選擇搜索按鈕時,不會出現結尾的新行。

我該如何解決這個問題? 有沒有更好的解決方案來做到這一點?

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(); 
     } 
    } 
} 
+0

當您選擇一行時,您希望將其顯示爲GRID結尾的新行? –

回答

0

它已被更新等之後,你可以刷新數據源:

DataGridView view = new DataGridView(); 
view.DataSource = somesource; 
view.DataSource = null; 
view.DataSource = updatedsource; 

對不起,我不能發表評論,但這應該幫助。 另請參閱:How can I refresh c# dataGridView after update ?