datagrid内嵌combox

    技术2024-10-20  24

    '在窗体上放一个DataGrid1和一个ComboBox1,将Datagrid1的行高设置和combobox1的高度一致 Private Sub datagrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer) On Error GoTo ErrCode      ComboBox1.Visible = False       If DataGrid1.Col > 0 And DataGrid1.Row > = 0 Then       ComboBox1.Left = DataGrid1.Columns(DataGrid1.Col).Left       ComboBox1.Top = DataGrid1.RowTop(DataGrid1.Row)       ComboBox1.Width = DataGrid1.Columns(DataGrid1.Col).Width       End If       If DataGrid1.Col = 2 Then '这一列显示combobox1        ComboBox1.Visible = True       End If       ErrCode: End Sub Private Sub datagrid1_ColResize(ByVal ColIndex As Integer, Cancel As Integer)       ComboBox1.Visible = False End Sub Private Sub datagrid1_RowResize(Cancel As Integer) On Error GoTo ErrCode       ComboBox1.Visible = False       If DataGrid1.RowHeight > 300 Then       DataGrid1.RowHeight = 300 ErrCode: End Sub Private Sub datagrid1_Scroll(Cancel As Integer) On Error GoTo ErrCode         ComboBox1.Visible = False ErrCOde: End Sub Private Sub combobox1_Click() On Error GoTo ErrCode        If ComboBox1.Text <> " " Then DataGrid1.Text = ComboBox1.Text        DataGrid1.SetFocus ErrCode: End Sub Private Sub combobox1_KeyPress(KeyAscii As Integer)       If KeyAscii = 13 Then combobox1_Click End Sub Private Sub datagrid1_HeadClick(ByVal ColIndex As Integer) On Error GoTo ErrCode          ComboBox1.Visible = False ErrCode: End Sub
    最新回复(0)