DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Using DBGrid

  1. #1
    Join Date
    Aug 2004

    Using DBGrid

    [Originally posted by Mr. D]

    Hello. 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?

    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)
    cmbDataInput.Width = ocolumn.Width
    cmbDataInput.Left = DBGrid1.Left + ocolumn.Left
    cmbDataInput.Top = DBGrid1.Top + DBGrid1.RowTop(DBGrid1.row)
    cmbDataInput.Visible = True
    SetupCombo ColIndex

    ElseIf ColIndex = 2 Then
    Set ocolumn = DBGrid1.Columns(ColIndex)
    With MaskRefDate
    .Width = ocolumn.Width
    .Left = DBGrid1.Left + ocolumn.Left
    .Top = DBGrid1.Top + DBGrid1.RowTop(DBGrid1.row)
    .PromptInclude = False
    .Text = ""
    .PromptInclude = True
    .Visible = True
    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!

  2. #2
    Join Date
    Aug 2004

    I think you're using the combo box wrong

    [Originally posted by OJ]

    Hello there,

    I have used these controls in the past and I think you are using them incorrectly.

    You should be using the DBGrid and the DBDropDown controls.

    set myGrid.datasource = rsGridData
    set myDropDown.datasource = rsDropDownData
    myGrid.Columns("Address").DropDown = myDropDown

    This is simple to get what you need done.

    If you need any other help just ask.

    - OJ

  3. #3
    Join Date
    Aug 2004

    Re:I think you're using the combo box wrong

    [Originally posted by Mr. D]

    Thanks for the reply. Sorry for the late response. I have no Internet access during the Lenten season. Actually, I found the idea of putting a combo box on a dbgrid's cell to facilitate data input and validation somewhere in this site. Is the DBDropDown control you're saying included in the Components list? I can't find it listed. Do you have any other ideas on how I can implement data input and validation on a dbgrid? Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.