16,722
社区成员




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
[/quote]
试了下确实好用,之前不管用的问题还没看怎么回事。多谢大家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
'申请一个DataGridViewComboBoxCell
Dim l_dtgCell As New DataGridViewComboBoxCell
l_dtgCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox
Dim loc_dr_mulOBJ As OleDb.OleDbDataReader = comm.ExecuteReader
'为DataGridViewComboBoxCell加载元素
While loc_dr_mulOBJ.Read
l_dtgCell.Items.Add(loc_dr_mulOBJ("cMATERIEL_SPEC"))
End While
DgvObjScan.Rows(int_currentRow).Cells(4) = l_dtgCell
'如果开始有值,则在加载完Cbx后将该单元格设置为str_orgNote
If str_orgNote <> "" Then
DgvObjScan.Rows(int_currentRow).Cells(4).Value = str_orgNote
End If