Community discussion forum

Printing datagrids

  • 2 years ago
    Hey guys,

    a bit new to the whole database thingi. Im just wondering if i want to print everything which is on a datagrid how do i do it?

    I tried printer.print datagrid1 but the printer takes the paper in and just puts it out. can anyone help me please. Thanks a million in advance

    Elabuwa







  • 2 years ago
    Does the data in the datagrid coms from the table of the database? if it is... then
    Hope this would help...

    follow the steps below:




    1. Add Data Environment (click on the Project menu then select Add Data Environment)

    2. Add Data Report (click on the Project menu then select Add Data Report)
    3. In the Data Environment right-click the connection1 then select properties
    4. Select the Microsoft Jet 4.0 OLE DB Provider then click Next button
    5. Enter your database name or browse your database (.mdb file) then click the Test Connection if successful then click OK

    6. Right -click the connection1 then select Add Command (Command1 will appear)

    7. Right-click the Command1 then select Properties (a window will appear)

    8. Put your desired command name (example EmployeeReport)

    9. select connection1 in the connection

    10. In the database object select table
    11. In the object name select the table you want (example employee table)

    12. click OK
    13. Click and Hold down the EmployeeReport(the command1) then drag it to the DataReport1 in the Detail(section1) then release.



    just tell me if you have still question





    regards:

    jireh ('',)











  • 2 years ago
    Hi jireh,

    sorry for the late reply. thanks very much for the advise. worked just like a charm.

    Elabuwa





  • 2 years ago

     

    Hi

         Just try the following code :

            flxgrid.Width = Printer.Width - 500
            Printer.PaintPicture flxgrid.Picture, 500, 500
            Printer.EndDoc

         You may need to add some programming logics to print whole data on the grid.

  • 2 years ago
    hi i cannt get what your problam is. but i am suggesting the code. if you have unknown number of fields and want to print them then use following code ''i will be using flex grid in place of datagrid please change the code accordingly dim rst as new adodb.recordset dim i as integer 'i assume that first fixed row has column headings with fgrid for i = 0 to .cols-1 rst.fields.append .textmatrix(0,i),adbstr 'you must make a valid field name before using column header ' e.g. remove spaces or dots etc in coulmn header ' so store column header to a variable then make it a valid field name next rst.open 'push data to recordset dim ii as integer dim lRows as long lrows = .rows for ii = .fixedrows to lRows -1 rst.addnew for i = 0 to .cols -1 rst.fields(i).value = .textarray(ii * .cols + i) next next end with ''now add a data report in the project in vb6 you cannot add contorls to dataReport on runtime 'so you have to fix the upper limit of columns in the report ' draw 30 lables and 30 text controls in the data report ' name lables as lbl0, lbl1, lbl2 .... and so on ' name text controls as txt0,txt1 ... and so on ' now add following code in the form with dataRport .datamember = "" set .datasource = rst const max_control = 30 for i = 0 to fgrid.textmatrix.cols -1 .sections("PageHeader").controls("lbl" & i).caption = fgrid.textmatrix(0,i) .sections("Detail").controls("txt" & i).datamember = "" .sections("Detail").controls("txt" & i).datafield = fgrid.textmatrix(0,i) '' validdate field name as i mentioned earlier next ' if fields in the recordset are less than 30 then for ii = i to max_controls .sections("PageHeader").controls("lbl" & i).visible = false .sections("Detail").controls("txt" & i).datamember = "" .sections("Detail").controls("txt" & i).datafield = fgrid.textmatrix(0,0) .sections("Detail").controls("txt" & i).visible = false next 'change orientation if neccessary .orientation = rptLandScape .refresh .show .setfous end with hope this will help you regards manpreet singh dhillon hoshiarpur
  • 2 years ago

    Hi there,

     got the problem sorted out. Thanks very much

     

    Elabuwa

  • 2 years ago

    hello friend,

      

     

  • 2 years ago

    hello friend,

      

     

     
  • 2 years ago

    hello friend,

      

     

     
  • 2 years ago

    hello my friend,

        i had the same problem with the member whom u sent the above instructions..i had already done the above instrcutions..what i want to learn from u is what will be the code behind my command button "PRINT" on the form....this is how my form or program flows....

             the datagrid on the upper right side of the form dipplays the record(s) based on the customized search from the user. Records displayed is changing..then when i click "PRINT" the records will diplay/transfered to data report, for them to be printed..so what  would be VB code for the command button PRINT?

    thank you, hope u cud help me here again. my friend..

    have a nice day

     

    laser 

     

  • 2 years ago

     

    Hi Laser, If you follwed the instructions then you have already created a datagrid. Just type what ever datagridsname.show

     

    eg : datagrid1.show

     

    Then it will show the table in a print preview sort of thing and there is the print butt9on on the top left. just click that

     

    Good luck

    Elabuwa

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!