2012-03-28 30 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