2013-11-28 25 views
2

所有,我用下面的代碼在DataGridView中添加一個全選複選框。到目前爲止它工作正常。但標籤索引順序仍然存在問題。請檢查它。DataGridView選項卡索引順序裏面的控件

 for (int i = 0; i < 3; i++) 
     { 
      dataGridView1.Rows.Add(); 
      DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[i]; 


      row.Cells[0].Value = true; 
      row.Cells[1].Value = "cell"; 
      row.Cells[2].Value = "cell"; 
     } 
     Rectangle rect = 
      this.dataGridView1.GetCellDisplayRectangle(0, -1, true); 

     checkBox1.Location = rect.Location; 
     checkBox1.Left = 9; 
     checkBox1.Top = 3; 

     dataGridView1.Controls.Add(checkBox1); 

我在設計時間中所需的Tab順序設置如下所示。

enter image description here

但在運行時.The選項卡順序是怪異。複選框選項卡順序始終位於DataGridView的所有單元格的後面。並且如果複選框不包含在網格中。訂單會很好。它將遵循設計順序。 有什麼方法可以解決它嗎?謝謝。 enter image description here

+0

您是否嘗試設置TabIndex屬性?當您將控件放置在表單中時,它們的索引默認設置爲放置它們。 – Iale

+0

Hi lale,你有沒有在設計器中使用'TabOrder'函數?它位於「View-TabOrder」菜單下,並且它使用代碼設置TabIndex屬性。謝謝。 –

+0

是的,我做到了。我已經更新了我的答案 – Iale

回答

0

我認爲訂單是通過將checkBox1移動到dataGridView控件集合中斷的。您應該在該控件中處理選項卡。這可以通過創建自定義DataGridView並重寫ProcessTabKey方法來完成See

相關問題