Click to See Complete Forum and Search --> : Using DBGrid


daneb
April 26th, 2001, 03:37 AM
Hi. I have several questions regarding the use of DBGrid.

1)
I have a dbgrid, named DBGrid1. I need to detect the row and column where the user clicked. I used the Click, ColEdit, RowColChange events, but to no avail. Furthermore, the DBGrid1.row and DBGrid1.col return wrong values. Sometimes, the return values were those from a previous click. How can I determine the exact row & column as clicked by the user?

2)
Is it possible to lock a cell thereby disabling it for input? In the Properties page, an entire column can be locked. What if you need to lock certain cells in a column only?

3)
I also used the DBGrid1_ButtonClick event, because I need to display a combo box (named CmbDataInput) on certain columns and a masked edit box (MaskRefDate) on the third column to facilitate data inputting. Why is it that it takes two clicks (not double click) to be able to use this event: the first click on a cell will display the drop-down arrow, the second click will display the combo box or the masked edit box itself. Even if I use the masked edit box, a drop down arrow is still shown, which makes a little confusing, the user might think that a combo box will appear at first. How can I activate the combo and the masked edit box immediately?

My code for this follows:

Private Sub DBGrid1_ButtonClick(ByVal ColIndex As Integer)

If ColIndex = 3 Or ColIndex = 4 Or ColIndex = 5 Or ColIndex = 6 Or ColIndex = 9 Or ColIndex = 15 Or ColIndex = 16 Then
Set ocolumn = DBGrid1.Columns(ColIndex)
' POSITION COMBO BOX
cmbDataInput.Width = ocolumn.Width
cmbDataInput.Left = DBGrid1.Left + ocolumn.Left
cmbDataInput.Top = DBGrid1.Top + DBGrid1.RowTop(DBGrid1.row)
cmbDataInput.Visible = True
' LOAD DATA IN COMBO BOX
SetupCombo ColIndex

ElseIf ColIndex = 2 Then
Set ocolumn = DBGrid1.Columns(ColIndex)
' POSITION MASKED EDIT BOX
With MaskRefDate
.Width = ocolumn.Width
.Left = DBGrid1.Left + ocolumn.Left
.Top = DBGrid1.Top + DBGrid1.RowTop(DBGrid1.row)
.PromptInclude = False
.Text = ""
.PromptInclude = True
.Visible = True
.SetFocus
End With
End If

End Sub

SetupCombo is a subroutine that will load the combo box with values from a database table, dynamically.

Thanks in advance for any suggestions and tips!