How to set value to DataGridViewComboBox Column?

前端 未结 5 1500
盖世英雄少女心
盖世英雄少女心 2020-12-09 21:51

I want to know how to set the value of a DataGridViewComboBox cell. I already bind the DataGridViewComboBox with DataSource. But I want to set new value to this this datasou

5条回答
  •  自闭症患者
    2020-12-09 21:58

    This worked for me

    dim dt as datatable
    dt=fillMydata()  'do your function
    'dt has 2 col myId as myDescription
    Dim col As DataGridViewComboBoxColumn
    col = New DataGridViewComboBoxColumn
    col.HeaderText = "MyHeader"
    col.Name = "Myname"
    col.DataSource = data   '
    col.DisplayMember = "myDescription"
    col.ValueMember = "myId"
    col.DropDownWidth = 240
    
    ''''''''''''''''''''''''''''''''''''''''''''''
    'set the value
    col.DefaultCellStyle.NullValue = dt.Rows(0).Item("myDescription").ToString
    ''''''''''''''''''''''''''''''''''''''''''''''
    
    DataGridView1.Columns.Add(col)
    

    hope this help

提交回复
热议问题