2012-03-28 29 views
1

我有三種形式:的DataGridView刷新窗口C#桌面應用程序

  1. Form1中(這是MDI)
  2. 窗體2(MDI的孩子)
  3. Form3(窗體2的小孩)

在我的應用程序Form1(MDI)首先打開,其中子窗體(Form2)已打開菜單,現在Form2有linkBut​​ton,當我單擊另一個窗體(Form3)時已打開。 Form3具有Form3的formLoad上的DataGridView1。

我想要的DataGridView1綁定後,其第二行應該作爲選定。 對於我寫這段代碼:

DataGridView1.Rows[1].Selected = true; // 1 is the index of that row. 

但是這個代碼不工作,問題是,DataGridView的是沒有得到刷新。

+0

u能提供相關的代碼? – Coder 2012-03-28 10:32:49

+0

@ coder抱歉,實際上它對我來說很難在這裏放置一個代碼,這是令人困惑的。只有我想要的東西,即我的DataGridView1不刷新,即使使用DataGridView1.Refresh()Function.Or後,您可以說我的DataGridView1在將Selected屬性設置爲true後不再重新繪製。 – 2012-03-28 10:42:49

回答

1

你可以試試這個

DataGridView1.CurrentCell = DataGridView1[0, 1] 
0

不確定如果我仍然遇到問題,您是否在Form.Load事件上執行行選擇並且它不起作用?嘗試在Form.Activated事件中使用您的代碼。

0

你要綁定的數據源偶爾

DataGridView1.DataSource = YOUR_DATA_SOURCE; 

然後

DataGridView1.Rows[0].Selected = true; 
DataGridView1.CurrentCell = DataGridView1.Rows[1].Cells[0]; 
+0

謝謝@Vishal,我得到了答案。 – 2012-03-28 10:52:58