簡體   English   中英

Datagridview刷新窗口C#桌面應用程序

[英]Datagridview Refresh window c# desktop application

我有三種形式:

  1. Form1(哪個是Mdi)
  2. Form2(MDI的子代)
  3. Form3(Form2的子代)

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

我想要的是,在綁定DataGridView1之后,它的第二行應為選中狀態。 為此,我正在編寫以下代碼:

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

但是此代碼無法正常工作,問題在於DataGridView沒有得到刷新。

你可以試試這個

DataGridView1.CurrentCell = DataGridView1[0, 1]

不確定我是否仍然遇到問題,是否是您在Form.Load事件上進行了行選擇而導致的問題呢? 嘗試在Form.Activated事件中使用您的代碼。

您有時需要綁定數據源

DataGridView1.DataSource = YOUR_DATA_SOURCE;

然后

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM