|
-
Jun 19th, 1999, 11:34 AM
#1
Thread Starter
New Member
I am trying to make a database with the dbgrid control. So far, I have added 10 columns and set the columns's names and captions. But how do you add rows to the grid by code? The code I have so far goes as follows:
The following is inserted into the general section of a module.
'toy stands for time of year(date screws things up)
Public RXNUMBER, TOY, ROOM, PNAME, DIRECT, DRUGNAME, STRENGTH, _
AMOUNT, DOCTOR, OTHERDIR As Column
The following is a funtion that will set up the columns and rows of the dbgrid.
Function SetUpData()
'add columns
Dim x As Integer
x = 1
Do
Form1.DBGrid1.Columns.Add 0
x = x + 1
Loop Until x = 10
Set RXNUMBER = Form1.DBGrid1.Columns(1)
Set TOY = Form1.DBGrid1.Columns(2)
Set ROOM = Form1.DBGrid1.Columns(3)
Set PNAME = Form1.DBGrid1.Columns(4)
Set DIRECT = Form1.DBGrid1.Columns(5)
Set DRUGNAME = Form1.DBGrid1.Columns(6)
Set STRENGTH = Form1.DBGrid1.Columns(7)
Set AMOUNT = Form1.DBGrid1.Columns(8)
Set DOCTOR = Form1.DBGrid1.Columns(9)
Set OTHERDIR = Form1.DBGrid1.Columns(10)
RXNUMBER.Visible = True
TOY.Visible = True
ROOM.Visible = True
PNAME.Visible = True
DIRECT.Visible = True
DRUGNAME.Visible = True
STRENGTH.Visible = True
AMOUNT.Visible = True
DOCTOR.Visible = True
OTHERDIR.Visible = True
RXNUMBER.Caption = "Rx Number"
TOY.Caption = "Date"
ROOM.Caption = "Room #"
PNAME.Caption = "Patient Name"
DIRECT.Caption = "Directions"
DRUGNAME.Caption = "Drug Name"
STRENGTH.Caption = "Strength"
AMOUNT.Caption = "Amount"
DOCTOR.Caption = "Doctor"
OTHERDIR.Caption = "Other Directions"
RXNUMBER.Width = 900
TOY.Width = 800
ROOM.Width = 800
DIRECT.Width = 2000
DRUGNAME.Width = 1100
STRENGTH.Width = 800
AMOUNT.Width = 800
DOCTOR.Width = 1000
OTHERDIR.Width = 1900
End Function
This funtion works to set up the columns of the grid, but how do you insert rows by code?
ANY HELP WOULD BE GREATLY APPRECIATED.
-
Jun 20th, 1999, 11:36 AM
#2
Junior Member
If you bind to a table, the grid will set itself to the number of records in the table. You can set the VisibleRows property whether the DBgrid is bound to a table or not.
------------------
-
Jun 23rd, 1999, 11:53 AM
#3
New Member
Try this code:
private Sub cmdAddRow_Click()
dim ncount as integer
ncount = MSFlexGrid1.Rows
'*'to add rows if GRID filled out , but additional row is needed
'*'1. Check, if now free space for data still available
'*'2. Add One row:
If MSFlexGrid1.TextMatrix(ncount - 1, 0) <> "" Then
MSFlexGrid1.Rows = ncount + 1
ncount = ncount + 1
MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
MSFlexGrid1.Col = 1
MSFlexGrid1.CellBackColor = &H8000000F
MSFlexGrid1.GridColor = vbBlack
End If
-
Jun 26th, 1999, 11:35 AM
#4
Lively Member
i dont know if it helps, but if you use the data object, try this code and check what it dode:
data1.recordset.addnew
-
Jun 26th, 1999, 06:24 PM
#5
Thread Starter
New Member
Thanks everyone! The data1.recordset.addnew turned out to be the most effective way to do it. Thanks again, and if ya have the time, take a look at my other topic...I would really appreciate it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|