dcsimg
Results 1 to 5 of 5

Thread: how to print entire data in datagrid?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Question how to print entire data in datagrid?

    Hi, how to use printer.print entire data in datagrid? this code is only can print
    selected row in datagrid.

    mycode:
    Code:
    Private Sub Print1_Click()
    
    Dim i As Integer
    
    For i = 0 To DataGrid1.Columns.Count - 1
    DataGrid1.Col = i
    
    Printer.Print DataGrid1.Text
    
    Next
    
    Printer.EndDoc
    
    End Sub
    Your help is much appreciated.


  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: how to print entire data in datagrid?

    You have to loop through each row and then through each column.
    However, I would recommend to design report - there are various utilities available including VB6 Data Report (free), Crystal Reports (commercial), Active Reports (commercial), many others...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Unhappy Re: how to print entire data in datagrid?

    hi,
    Actually I want is when I mark checkbox [Print all] and click Print button then all data from datagrid will print out the barcode label and changing the data as I attach the file, i want is how to loop and print all data from datagrid like my output barcode format accordingly.
    I need my project urgently, thank you.

    Please provide example code.
    Code:
    Private Sub Print1_Click()
    
    If COM1.Value = True Then
    MSComm1.CommPort = 1
    Else
    COM1.Value = False
    LPT1.Value = True
    End If
    
    If LPT1.Value = False Then
    MSComm1.PortOpen = True
    If MSComm1.DSRHolding = False Then
        MsgBox "Printer Not Ready", vbCritical, "Error"
        MSComm1.PortOpen = False
        Exit Sub
    End If
    End If
    
    If MsgBox("      Are you sure to print", vbOKCancel, "Print") = vbCancel Then
    Exit Sub
    End If
    
    qtty = Format$(Val(qtytxt.Text), "0000")
    
    'Print only 1 label
    If LPT1.Value = True Then
    
    'label format
    LabelFormat
    
    End If
    End Sub
    
    Public Sub LabelFormat()
    
    Printer.Print "{D0391,0919,0360|}"
    Printer.Print "{C|}"
    Printer.Print "{D0391,0919,0360|}"
    Printer.Print "{AX;+000,+000,+00|}"
    Printer.Print "{AY;+00,0|}"
    Printer.Print "{PC000;0007,0144,15,20,K,00,B|}"
    Printer.Print "{RC00;" & Text1.Text & "|}"
    Printer.Print "{XB00;0030,0190,A,3,03,0,0149,+0000000000,000,0,00|}"
    Printer.Print "{RB00;>5>8>6" & Text1.Text & "|}"
    Printer.Print "{XB01;0706,0035,A,3,02,0,0142,+0000000000,000,0,00|}"
    Printer.Print "{RB01;>5>8>6" & Text2.Text & "|}"
    Printer.Print "{PC001;0718,0320,10,20,K,00,B|}"
    Printer.Print "{RC01;" & Text2.Text & "|}"
    Printer.Print "{XS;I," & qtty & ",0002C6200|}"
    Printer.EndDoc
    
    End Sub
    Attached Images Attached Images  

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: how to print entire data in datagrid?

    Quote Originally Posted by hwkong1688 View Post
    I need my project urgently, thank you.
    There is no such thing as urgency on this forum - everybody's a volunteer and can only respond on their free time.
    If you know how to loop through columns you should be able to figure how to loop through rows as well (below is pseudo code):
    Code:
    For each row
        for each column
            'print code goes here...
        next column
    next row
    However, for each new page (which you need to calculate manually) you'll have to print new header, footer, column headers, etc, etc...
    Instead, as I already mentioned use report designer to avoid lots of headache.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Re: how to print entire data in datagrid?

    Thank Rhino,now can print out already..but how to print all data?? and i don't know where to put my LabelFormat printing code on this:-

    This code work fine.
    Code:
    DataGrid1.row = 0
    DataGrid1.Col = Colomn1
    For Colomn1 = 0 To DataGrid1.Columns.Count - 1
    DataGrid1.Col = Colomn1
    Debug.Print DataGrid1.Text
    
    Next
    
    
    Colomn1 = 0
    DataGrid1.Col = Colomn1
    For RRow = 0 To 10 'how to print all data in this line
    DataGrid1.row = RRow
    For Colomn1 = 0 To DataGrid1.Columns.Count - 1
    DataGrid1.Col = Colomn1
    Printer.Print DataGrid1.Text
    Next
    Next
    
    Printer.EndDoc
    my printing format
    Code:
    Public Sub LabelFormat()
    
    Printer.Print "{D0391,0919,0360|}"
    Printer.Print "{C|}"
    Printer.Print "{D0391,0919,0360|}"
    Printer.Print "{AX;+000,+000,+00|}"
    Printer.Print "{AY;+00,0|}"
    Printer.Print "{PC000;0007,0144,15,20,K,00,B|}"
    Printer.Print "{RC00;" & Text1.Text & "|}"
    Printer.Print "{XB00;0030,0190,A,3,03,0,0149,+0000000000,000,0,00|}"
    Printer.Print "{RB00;>5>8>6" & Text1.Text & "|}"
    Printer.Print "{XB01;0706,0035,A,3,02,0,0142,+0000000000,000,0,00|}"
    Printer.Print "{RB01;>5>8>6" & Text2.Text & "|}"
    Printer.Print "{PC001;0718,0320,10,20,K,00,B|}"
    Printer.Print "{RC01;" & Text2.Text & "|}"
    Printer.Print "{XS;I," & qtty & ",0002C6200|}"
    
    Printer.EndDoc
    End Sub

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width