Results 1 to 9 of 9

Thread: dbgrid

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    21

    Post


    How to work with a unbound dbgrid control.
    I am not able to add or enter any rec in runtime?IT looks like the row is disabled.
    Can i populate dbgrid at runtime?

    By the way can i get vb 6.0 s/w online.If yes
    please give me the site

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Are you asking 1) how to get the program to show data in the unbound grind, or 2) how can a user enter data in the unbound grid?

    ------------------
    Marty

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    For 2) if you will send me an email, I will reply with a demo project that shows how to allow the user to enter data into a grid. It uses the MSFlexGrid, but the same principals apply to DBGrid.

    Here is an example that shows how to load a DBGrid witn data from a database:
    Code:
    Option Explicit
    
    Private mdbMyDatabase As Database
    
    Private Sub Form_Load()
    
        Set mdbMyDatabase = Workspaces(0).OpenDatabase(App.Path + "\My.mdb")
        LoadGrid
    
    End Sub
    
    Sub LoadGrid()
    '***************************************************************************
    'Purpose: Load Grid1
    'Inputs:  None
    'Outputs: None
    '***************************************************************************
        Dim rsRecs As Recordset
        Dim nRow As Integer
        
        On Error GoTo ErrorRoutine
    
        Set rsRecs = mdbMyDatabase.OpenRecordset("Select * From IntegrationType", dbOpenSnapshot)
        ' Find out how many records in the record set and size the grid
        rsRecs.MoveLast
        Grid1.Rows = rsRecs.RecordCount
        
        rsRecs.MoveFirst
        
        Do Until rsRecs.EOF
            Grid1.Row = nRow
            Grid1.Col = 0
            Grid1.Text = rsRecs!IntegrationType
            Grid1.Col = 1
            Grid1.Text = rsRecs!Basic
            rsRecs.MoveNext
            nRow = nRow + 1
        Loop
        
        rsRecs.Close
        
    ErrorRoutine:
    
        'If Err.Number <> 0 Then DisplayError "LoadGrid"
    
    End Sub
    ------------------
    Marty

    [This message has been edited by MartinLiss (edited 11-11-1999).]

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    21

    Post

    I want both.Help me....

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    It needs to be rec.recordcount rather than rec!recordcount. "." is used for properties of the recordset, and "!" is used for fields in the recordset.

    ------------------
    Marty

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Please post the Sub or Function (or send it to me in an email) and I'll take a look at it, because my code as shown works just fine.

    ------------------
    Marty

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    21

    Post

    Private mdbMyDatabase As Database

    Private Sub Form_Load()
    Set mdbMyDatabase = Workspaces(0).OpenDatabase("C:\NEWDB.MDB")
    LoadGrid
    End Sub

    Sub LoadGrid()
    Dim rs As Recordset
    Dim nRow As Integer
    Set rs = mdbMyDatabase.OpenRecordset("Select * From DEPT", dbOpenSnapshot)
    rs.MoveLast
    'MsgBox rs.RecordCount
    DBGrid1.Rows = rs.RecordCount 'ERROR HERE
    rs.MoveFirst
    Do Until rs.EOF
    DBGrid1.Row = nRow
    DBGrid1.Col = 0
    DBGrid1.Text = rs!DNO
    DBGrid1.Col = 1
    DBGrid1.Text = rs!DNAME
    rs.MoveNext
    nRow = nRow + 1
    Loop
    rs.Close


    End Sub

    I ADDED MICROSOFT DATA BOUND GRID CONTROL FROM MY COMPONENTS. I changed the bound property to unbound .I don't know where iam making a mistake?Just add a dbgrid control and paste the code i have given. tell me whether it works or not.

    hey!! thanx for taking time and replying.

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I don't use the data bound controls (I don't think any sane person would ) but when I tried your code I saw that the DBGrid does not have a Rows property and that is why you got the error. That makes sense I guess because the number of rows a databound control would normally be handled by VB. I think the solution is for you to change from the DBGrid to the Grid or MSFlexGrid control. Why use the DBGrid if it's unbound?

    ------------------
    Marty

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    21

    Post

    Actually i have written rec.recordcount only
    But the error is near method grid1.ROWS

    [This message has been edited by shan1 (edited 11-12-1999).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width