有一个包含不同类型列的datagridview。 现在我想添加一行,由不同的单元格组成。我不能将单元格定义为datagridviewcell,但必须将其定义为textboxcell或comboboxcell等。但我想让它取决于列的类型..我不能让它工作。
数据来自数据集,但只获取datagridview中所需的数据表中的数据。因此,我无法将datagridview绑定到数据表。
For Each dr As DataRow In dt.Rows
Dim rij As New DataGridViewRow
For i = 0 To dgOrder.ColumnCount - 1
''Dim cel As New DataGridViewTextBoxCell 'does work but Must already define value type......
''Dim cel As dgOrder.Columns(i).CellType 'does not work
''Dim CEL As DataGridViewCell '' does not work because value is not assigned
''CEL.ValueType = dgOrder.Columns(i).CellType ''doesn't help
columntext = dgOrder.Columns(i).Name
''CEL.Style = dgOrder.Columns(i).DefaultCellStyle
CEL.Value = dr.Item(columntext)
rij.Cells.Add(CEL)
Next
dgOrder.Rows.Add(rij)
Next
有人知道如何使用dim cel作为datagridviewcell或如何使用正确的datagridviewcelltype定义cel?