1. 继承DataGridColumnStyle完成向DataGrid中添加ComboBox。
  2. vb6
    要在Datagrid 中添加ComboBox,擦采用如下方法:
      
    Dim MyCombo As New ComboBox
         
    添加到Datagrid格式化中
     
    AddHandler MyCombo.TextChanged, AddressOf Ctrls_TextChanged
            
    '设置MyCombo的Name以及Visible属性
            MyCombo.Name = "MyCombo"
            MyCombo.Visible 
    = False
            MyCombo.DropDownStyle 
    = ComboBoxStyle.DropDown
            
    '清空MyCombo
            MyCombo.Items.Clear()
            
    '给MyCombo添加项
           Me.MyCombo.Items.Add(" ")

            
    '把MyCombo加入到dgdGoodInfo的Controls集合中
            dgdGoodInfo.Controls.Add(MyCombo)

    添加函数,MyCombo 添加到第四列
    Private Sub Ctrls_TextChanged(ByVal sender As Object, _
        
    ByVal e As System.EventArgs)
            
    '判断DataGrid的当前单元格是否属于第四列
            'DataGrid的列是从0开始
            If dgdInfo.CurrentCell.ColumnNumber = 4 Then
                
    If dgdInfo.Item(dgdInfo.CurrentCell) & "" = "" Then
                    SendKeys.Send(
    " ")
                
    End If
                
    '设置当前单元格的值为MyCombo选中的项的Text
                dgdInfo.Item(dgdInfo.CurrentCell) = MyCombo.Text
            
    End If
        
    End Sub

        
    Private Sub dgdInfo_Click(ByVal sender As Object, _
        
    ByVal e As System.EventArgs) Handles dgdInfo.Click
            
    '设置MyCombo的Visible,Width属性
            MyCombo.Visible = False
            MyCombo.Width 
    = 0
        
    End Sub

        
    Private Sub dgdInfo_CurrentCellChanged(ByVal sender _
        
    As ObjectByVal e As System.EventArgs) Handles _
        dgdInfo.CurrentCellChanged
            
    If dgdInfo.CurrentCell.ColumnNumber = 4 Then
                MyCombo.Visible 
    = False
                MyCombo.Width 
    = 0
                MyCombo.Left 
    = dgdInfo.GetCurrentCellBounds.Left
                MyCombo.Top 
    = dgdInfo.GetCurrentCellBounds.Top
                MyCombo.Text 
    = _
                dgdGoodInfo.Item(dgdInfo.CurrentCell) 
    & ""
                MyCombo.Visible 
    = True
            
    Else
                MyCombo.Visible 
    = False
                MyCombo.Width 
    = 0
            
    End If
        
    End Sub

        
    Private Sub dgdInfo_Paint(ByVal sender As Object, _
        
    ByVal e As PaintEventArgs) Handles dgdGoodInfo.Paint
            
    If dgdInfo.CurrentCell.ColumnNumber = 4 Then
                MyCombo.Width 
    = dgdInfo.GetCurrentCellBounds.Width
            
    End If
        
    End Sub

        
    Private Sub dgdInfo_Scroll(ByVal sender As Object, _
        
    ByVal e As System.EventArgs) Handles dgdInfo.Scroll
            MyCombo.Visible 
    = False
            MyCombo.Width 
    = 0
        
    End Sub
    注:dgdInfo 为DataGrid.

相关文章:

  • 2021-11-27
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2022-12-23
  • 2021-05-30
  • 2021-10-03
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案