0
私はDataGridでプログラムでコンボボックス列を作成しました。初期化プロセスの一環として、デフォルト値をいくつか設定したいと思います。しかし、それは動作していません。コードは以下の通りです。VB.netでデータグリッドのcomboboxcolumn値を動的に変更
DataGridView1.ColumnCount = 1
With DataGridView1.ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(DataGridView1.Font, FontStyle.Bold)
End With
With DataGridView1
.Name = "songsDataGridView"
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = False
.Columns(0).Name = "Select S "
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
End With
Dim cmb1 As New DataGridViewComboBoxColumn()
cmb1.HeaderText = "Type"
cmb1.Name = "cmb"
cmb1.MaxDropDownItems = 3
cmb1.Items.Add("T")
cmb1.Items.Add("R")
cmb1.Items.Add("T/R")
DataGridView1.Columns.Add(cmb1)
Dim cmb2 As New DataGridViewComboBoxColumn()
cmb2.HeaderText = "Domain"
cmb2.Name = "cmb"
cmb2.MaxDropDownItems = 5
cmb2.Items.Add("A")
cmb2.Items.Add("F")
cmb2.Items.Add("H")
cmb2.Items.Add("F")
cmb2.Items.Add("P")
DataGridView1.Columns.Add(cmb2)
Dim cmb3 As New DataGridViewComboBoxColumn()
cmb3.HeaderText = "Side"
cmb3.Name = "cmb"
cmb3.MaxDropDownItems = 8
cmb3.Items.Add("Left")
cmb3.Items.Add("Right")
cmb3.Items.Add("Top")
cmb3.Items.Add("Down")
cmb3.Items.Add("TopLeft")
cmb3.Items.Add("TopRight")
cmb3.Items.Add("DownLeft")
cmb3.Items.Add("DownRight")
DataGridView1.Columns.Add(cmb3)
Dim collocationiD As New DataGridViewTextBoxColumn()
With collocationiD
.HeaderText = "Location ID"
.Name = "sn3"
.Width = 60
.ReadOnly = True
End With
DataGridView1.Columns.Insert(4, collocationiD)
Dim cmb4 As New DataGridViewComboBoxColumn()
cmb4.HeaderText = "No of partitions"
Dim additem As Integer = 1
cmb4.Name = "cmb4"
cmb3.MaxDropDownItems = 32
Do
cmb4.Items.Add(additem)
additem = additem + 1
Loop Until additem = cmb3.MaxDropDownItems.ToString
DataGridView1.Columns.Add(cmb4)
ここで、データグリッドのデフォルト値を設定しようとしています。
DataGridView1.Rows(1).Cells(2).Value = "T"