Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » VB6 Datagrid problem pls help!!
Closed Thread
Old 06-09-2004, 07:11 PM   #1 (permalink)
 
Wizard Techie

Join Date: Apr 2004

Posts: 3,248

killians45

Default VB6 Datagrid problem pls help!!

Hey all, I'm writing a program that does the following:

access a sql server and then take the recordset and set it to a datagrid on a seperate form (have to have several seperate forms as this is a search function for several different areas.) The problem I'm having is in printing the data from datagrid1 and datagrid2 (on same form). I dont want to use printform (frmzy.printform) because it prints all as it sees it. Instead, I just want the data from the record sets and its headers to be printed. I know I can step through or add into an excel or text dump, but I figured there HAS to be a way to print just the raw data contained in the datagrid. Anyone have an idea on how to do this?
__________________
If you argue with an idiot he will drag you down to his level and beat you with experience.

I am not a fast writer.
I am not a slow writer.
I am a half-fast writer.

-Robert Asprin
killians45 is offline  
Old 06-09-2004, 08:09 PM   #2 (permalink)
 
Banned

Join Date: May 2003

Posts: 105

imported_Jack

Default

Depending on how you want to format the data you can either pull the data from the grid a cell at a time and then format and print it, or simply use something like crystal to report on your data.
imported_Jack is offline  
Old 06-09-2004, 08:22 PM   #3 (permalink)
 
Wizard Techie

Join Date: Apr 2004

Posts: 3,248

killians45

Default

esentially I'm plugging the rs straight into the datagrid so the rows and headers are updated dynamic. I think your right, I'll probably have to use crystal to report it. I just think its odd that there is no feature to actually print the data listed in the datagrid without having to create some sort of class. Here is a little more detail. I take a string call it sqlQuery and have it run like so: I'm omiting some of the line as its not pertinent....

select * from line9mfresults where rsltserialnumber_val0 between '" & param1 & "' and "' param2 "' and recordtype_val0 = '91' (or 93 depending on the algorythm results) order by " & param3

zyrs.open sqlquery.open, zyconn, adopenstatic

set datagrid1.datasource = zyrs

so now with the above it runs the query and then takes the query and directly plugs it into the datagrid1, headers and all. Unfortunatley, if I print the form it will of course print EVERYTHING, including the dull greyish background. I CAN get it to print the data, what I cant get it to do is print JUST the data and forget the actual form. Of course, printing all the data if it scrolls is another story, but I should be able to get that myself.

Long story short, yeah right , I know of other long ways to do this, but WHY OH WHY doesn't VB have a addin for this!!!! It seems to me to be COMPLETELY logical that this would be a must have with a datagrid. I mean, am I the only one who thinks this?
__________________
If you argue with an idiot he will drag you down to his level and beat you with experience.

I am not a fast writer.
I am not a slow writer.
I am a half-fast writer.

-Robert Asprin
killians45 is offline  
Old 06-13-2004, 09:22 PM   #4 (permalink)
 
Wizard Techie

Join Date: Apr 2004

Posts: 3,248

killians45

Default

In case anyone is wondering, I found the solution to this good aweful mess. Here is the code I used:

Private Sub PrintGrid(ctlGrid As Control)
Dim I As Integer
Dim J As Integer
Dim PTab As Integer

With ctlGrid
' PTab = 25 'Set the first tab value

For J = 0 To .Columns.count - 1
.Col = J 'Set the current column
If .Col = 0 Then
PTab = PTab + 25
ElseIf .Col = 1 Then
PTab = PTab + 25
ElseIf .Col = 2 Then
PTab = PTab + 32
ElseIf .Col = 3 Then
PTab = PTab + 20
ElseIf .Col = 4 Then
PTab = PTab + 18
ElseIf .Col = 5 Then
PTab = PTab + 18
ElseIf .Col = 6 Then
PTab = PTab + 35
ElseIf .Col = 7 Then
PTab = PTab + 30
End If
'Send the field to the print line and add the tab.
Printer.Print Trim$(.Columns(J).Caption); Tab(PTab);


Next
Printer.Print

For I = 0 To .ApproxCount - 1
PTab = 25 'Set the first tab value

'This checks to see if a page break is needed
If Printer.CurrentY + Printer.TextHeight(.Text) > Printer.ScaleHeight - 600 Then
Printer.NewPage
End If

For J = 0 To .Columns.count - 1
.Col = J 'Set the current column
If .Col = 0 Then
PTab = PTab + 25
ElseIf .Col = 1 Then
PTab = PTab + 25
ElseIf .Col = 2 Then
PTab = PTab + 32
ElseIf .Col = 3 Then
PTab = PTab + 20
ElseIf .Col = 4 Then
PTab = PTab + 18
ElseIf .Col = 5 Then
PTab = PTab + 18
ElseIf .Col = 6 Then
PTab = PTab + 35
ElseIf .Col = 7 Then
PTab = PTab + 30
End If
'Send the field to the print line and add the tab.
Printer.Print Trim$(.Text); Tab(PTab);

Next

Printer.Print

On Error Resume Next
.Row = .Row + 1 'Set the active row
On Error GoTo 0

Next I
End With
Printer.EndDoc
End Sub


and then with a print command button I added the line


Private Sub cmdprint_Click()

' DataReport1.PrintReport
Printer.Orientation = 2
Call PrintGrid(DataGrid3)

End Sub

of course you need to set datagrid 3 for that which I have in the form_load section (after the sql query is open and submitted) and saved as this

Set DataGrid3.DataSource = zyrsall
__________________
If you argue with an idiot he will drag you down to his level and beat you with experience.

I am not a fast writer.
I am not a slow writer.
I am a half-fast writer.

-Robert Asprin
killians45 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On