DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Thread: Using DBGrid

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    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)
    ÿ ÿ ÿ ÿ 'ÿ  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!

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    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
    Posts
    43,023

    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.

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links