All datagrid’s data print

0 pts.
Tags:
Development
Visual Basic
hi, when i find out the following code i implement it on my project and its working fine. that was very good. now i have 2 Questions. Dim RRow As Integer, CCol As Integer Printer.Print "" DataGrid1.Row = 0 DataGrid1.Col = CCol For CCol = 0 To DataGrid1.Columns.Count - 1 DataGrid1.Col = CCol Debug.Print DataGrid1.Text Next CCol = 0 DataGrid1.Col = CCol For RRow = 1 To 6 DataGrid1.Row = RRow For CCol = 0 To DataGrid1.Columns.Count - 1 DataGrid1.Col = CCol Printer.Print DataGrid1.Text Next Next Printer.EndDoc 1st:- i retreive data in datagrid from database according to my requirment.i.e if there are 3 Records it would be print 3. in print code i have loop for columns count but not for Rows. 2:- the print result on a paper in a single line not as shown in DataGrid. i want the print result on paper as shown in DataGird. All Columns Heading then All Rows as shown in DataGrid. Please help me in this regards. Thanks.
ASKED: September 1, 2006  6:40 PM
UPDATED: September 18, 2006  8:31 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

hi,

1. you can get the number of rows from the recordset you use to fill the datagrid. if you use ado it would be something like recordset.RecordCount. usually you can gain access to the recordset through the datagrid’s DataSource property.

2. to print the datagrid you can try the following code. however it’s only print the currently visible rows in the datagrid. to print all rows it’s more efficient if you print from the recordset directly. it was formatted to print each row in separate line, however if you want to align the columns properly you must calculate the maximum width of each column and insert additional vbTab(s) as appropriate.

‘Print column headers
For CCol = 0 To DataGrid1.Columns.Count – 1
Printer.Print DataGrid1.Columns(CCol).Caption & vbTab
Next
Printer.Print vbCrLf

‘Print visible rows
For RRow = 0 To DataGrid1.VisibleRows – 1
For CCol = 0 To DataGrid1.Columns.Count – 1
Printer.Print DataGrid1.Columns(CCol).CellText _
(DataGrid1.RowBookmark(RRow)) & vbTab
Next
Printer.Print vbCrLf
Next

hope this will help

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Qasimkhans
    thankx for your reply. i used this code but its not working. nothing happend. plz instructe me with other code. thankx
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following