2011-12-09 49 views
0

我有一個組合框,可以在窗體的完整刷新上顯示更改,但是新組合框最終會改變位置,並且不像您期望的那樣平滑過渡。當我更新文本框中的信息並使用保存按鈕時,我希望清除表單並使用組合框填充保存在數據庫中的新數據。這裏是我的代碼現在可行,但不是我喜歡的方式。如何刷新表單以填充數據庫更改,比.Hide/.Show更平滑?

 finally 
      { 
       con.Close(); 
       frmBooks mainForm = new frmBooks(); 
       mainForm.Show(); 
       this.Hide(); 
      } 

看起來要麼鎖定位置.Show()在同一位置或部分使用.REFRESH(),這將是非常簡單的,但是我在得到那個工作已經失敗。我正在使用VS 2010.

回答

1
frmBooks mainForm = new frmBooks(); 
mainForm.Show(); --- > Show new Form and 
this.Hide(); --> Hide Current open form 

也許你可以把你的組合框加載和清除方法上的字段,並在事件的任何地方調用它。

pivate void refreshForm() 
{ 

//you dsource 
cmbox.DataSource = youredsource 
cmbox.DisplayMember = "YouTableColumn"; 

textbox.text = string.Empty() 
//anything you want to clear 

} 

是這樣的:

 finally 
     { 
      con.Close(); 
      //refresh combo box and clear fields on form 
      refreshForm(); 
     } 

問候

相關問題