如何在datagridview

时间:2015-06-22 13:03:16

标签: combobox

如何在datagridview中为组合框分配值

Dim l As New ArrayList
        l.Add("Mouse")
        l.Add("Keyboard")
        l.Add("Laptop")


  CType(DataGridView1.Columns(0), DataGridViewComboBoxColumn).DataSource = l

1 个答案:

答案 0 :(得分:0)

Dim l As New ArrayList 
l.Add("Mouse") 
l.Add("Keyboard") 
l.Add("Laptop")

将ArrayList转换为字符串数组,或使用字符串数组而不是ArrayList

string[] items = (string[])l.ToArray(typeof(string));  

创建DataGridViewComboBoxColumn并将项目添加为范围

Dim comboBoxColumn = new DataGridViewComboBoxColumn();
comboBoxColumn.Name = "Options"
comboBoxColumn.Items.AddRange(items)

将列添加到datagridview的末尾

 DataGridView1.Columns.Add(comboBoxColumn)