Private Sub MoveCombo()
' In case of error, hide the ComboBox.
On Error GoTo Error_Handler
Dim gcol As MSDataGridLib.Column
Set gcol = DataGrid1.Columns(DataGrid1.col)
If gcol.Caption = "fieldname" And DataGrid1.CurrentCellVisible Then
' Move the ComboBox inside the column
' if it is the current column and it is visible.
combo1.Move DataGrid1.Left + gcol.Left, _
DataGrid1.Top + DataGrid1.RowTop(DataGrid1.row), gcol.Width
combo1.ZOrder
combo1.SetFocus
DataGrid1.RowHeight = combo1.Height
combo1.Text = gcol.Text
Exit Sub
End If
Error_Handler:
' In all other cases, hide the ComboBox.
combo1.Move _10000
If DataGrid1.Visible Then DataGrid1.SetFocus
End Sub
on the combobox
Private Sub combo1_Click()
' Change the value of the underlying grid cell.
DataGrid1.Columns("fieldname").Value = _
combo1.ItemData(combo1.ListIndex)
End Sub
then add the sub on the ff events of the datagrid
Private Sub DataGrid1_RowColChange(LastRow As Variant, _
ByVal LastCol As Integer)
MoveCombo
End Sub
Private Sub DataGrid1_RowResize(Cancel As Integer)
MoveCombo
End Sub
Private Sub DataGrid1_ColResize(ByVal ColIndex As Integer, _
Cancel As Integer)
MoveCombo
End Sub
Private Sub DataGrid1_Scroll(Cancel As Integer)
MoveCombo
End Sub
Private Sub DataGrid1_SplitChange()
MoveCombo
End Sub
i attached class module, how to use it correctly?
why it didn;t work? what's missing?
Code:
Private Sub DataGrid1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Dim a As ComboWithGrid
Set a = New ComboWithGrid
a.SetComboOnGrid Combo1, DataGrid1, 1, True
End Sub