读书人

怎么改变DataGridView指定单元格的Col

发布时间: 2013-07-11 15:38:46 作者: rapoo

如何改变DataGridView指定单元格的ColumnType属性
DGV编辑Column属性的窗口Edit Column中有ColumnType这一项,这项默认值是DataGridViewTextBoxColumn。
在生成的DGV中如何改变某一个单元格的这个属性?代码怎么写,点了半天也没点出这个属性来。
例如想改变第一行第二列的这个属性
Me.DataGridView1.Rows(0).Cells(1).后面该怎么写,或者是用其他方法改变
[解决办法]

引用:
DGV是普通的,想把第二行第二列的单元格设成有LINK的,参照您的代码写了下面两句

Dim cell As New DataGridViewLinkCell

Me.DataGridView1.Rows(1).Cells(1) = cell
显示出来还是原来模样。还需要设置哪里?


写在数据绑定之后
Dim cell As New DataGridViewLinkCell
cell.Value = "a12"
DataGridView1.Rows(0).Cells(0) = cell

Dim cell2 As New DataGridViewButtonCell
cell2.Value = "bbb"
DataGridView1.Rows(1).Cells(0) = cell2

Dim cell3 As New DataGridViewCheckBoxCell
cell3.Value = True
DataGridView1.Rows(2).Cells(0) = cell3


Dim cell4 As New DataGridViewImageCell
cell4.Value = My.Resources.excel
DataGridView1.Rows(3).Cells(0) = cell4
[解决办法]
引用:
再顶下,还有知道怎么回事的吗

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

读书人网 >VB Dotnet

热点推荐