PDA

Click to See Complete Forum and Search --> : dbgrid


shan1
Nov 10th, 1999, 01:47 AM
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

MartinLiss
Nov 10th, 1999, 04:15 AM
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

MartinLiss
Nov 11th, 1999, 12:30 AM
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:
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).]

shan1
Nov 11th, 1999, 11:10 AM
I want both.Help me....

MartinLiss
Nov 12th, 1999, 12:49 AM
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

MartinLiss
Nov 12th, 1999, 01:55 AM
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

shan1
Nov 12th, 1999, 02:53 AM
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.

MartinLiss
Nov 12th, 1999, 03:55 AM
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

shan1
Nov 12th, 1999, 11:06 AM
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).]