DataGridView中初始化DataGridViewComboBox列

上網查了查,有好些方法:參考http://www.itzhe.cn/article/20080317/114550.html

 

寫了一個初始化DataGridView中存在DataGridViewComboBox列的方法:

 

    string[] dataListMsg = new string[] {"a","b", "c"};

    string[] sLists = new string[] { "1", "2", "3"};

    //

    TestDataGridView.RowCount = dataListMsg.Length;
     //
     for (int i = 0; i < TestDataGridView.RowCount; i++)
     {
           TestDataGridView.Rows[i].Cells[0].Value = dataListMsg[i];
           TestDataGridView.Rows[i].Cells[1].Value = true;  //爲checkBox列
           DataGridViewComboBoxCell aCBCell = TestDataGridView.Rows[i].Cells[2] as 

                                          DataGridViewComboBoxCell;   //爲DataGridViewComboBox列
           if (aCBCell != null)
           {
               aCBCell.Items.AddRange(sLists );
               aCBCell.Value = sLists[0];   //設置初始值的關鍵
           }


     }

    

      希望對大家有幫助,歡迎大家提供更好的方法。

 

  

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章