如何改变DataGridView指定单元格的ColumnType属性
DGV编辑Column属性的窗口Edit Column中有ColumnType这一项,这项默认值是DataGridViewTextBoxColumn。
在生成的DGV中如何改变某一个单元格的这个属性?代码怎么写,点了半天也没点出这个属性来。
例如想改变第一行第二列的这个属性
Me.DataGridView1.Rows(0).Cells(1).后面该怎么写,或者是用其他方法改变
[解决办法]
Public Class Form1
'窗体上只需要拉出一个DataGridView,一个Button,其它什么也不用做
'你选中哪个单元格,就可将该单元格设置为ComboBoxCell类型
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = 6
DataGridView1.Rows.Add(10)
For i As Integer = 0 To 10
For j As Integer = 0 To 5
DataGridView1.Rows(i).Cells(j).Value = CInt(Rnd() * 1000)
Next
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If DataGridView1.CurrentCell.GetType.ToString = "System.Windows.Forms.DataGridViewComboBoxCell" Then
Exit Sub
End If
Dim Cell As New DataGridViewComboBoxCell
Dim a As Integer = DataGridView1.CurrentCell.RowIndex, b As Integer = DataGridView1.CurrentCell.ColumnIndex
For i As Integer = 0 To 5
Cell.Items.Add(DataGridView1.Rows(a).Cells(i).Value.ToString)
Next
DataGridView1.Rows(a).Cells(b) = Cell
End Sub
End Class