473,418 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

how to print all data from datagrid to printer??

Hi,this is my code for print data to my default printer,but not for all data.

1.How to print all data from datagrid to printer?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2.  
  3. Dim RRow As Integer
  4. Dim Colomn1 As Integer
  5.  
  6. DataGrid1.row = 0
  7. DataGrid1.Col = Colomn1
  8. For Colomn1 = 0 To DataGrid1.Columns.Count - 1
  9. DataGrid1.Col = Colomn1
  10. Debug.Print DataGrid1.Text
  11.  
  12. Next
  13.  
  14. Colomn1 = 0
  15. DataGrid1.Col = Colomn1
  16. For RRow = 0 To 5
  17. DataGrid1.row = RRow
  18. For Colomn1 = 0 To DataGrid1.Columns.Count - 1
  19. DataGrid1.Col = Colomn1
  20. Printer.Print DataGrid1.Text
  21. Next
  22. Next
  23.  
  24. Printer.EndDoc
  25.  
  26. End Sub
  27.  
Dec 27 '11 #1
11 10116
Killer42
8,435 Expert 8TB
Not sure what you mean. What does this code not print, that you want it to?
Dec 27 '11 #2
sorry make you confused, my question is how to print all data from datagrid to my default printer?
Dec 27 '11 #3
Killer42
8,435 Expert 8TB
@hwkong1688
All you've done is repeat the original question. It doesn't give us enough information to work with.

We need more detail to understand exactly what you want from us. You've shown us code which prints data to your default printer. As far as I can tell, you already have exactly what you're asking for. What is it about this code that you're not happy with? What does this code not do, that you want it to? In what way does your existing code not "print all data from datagrid to my default printer"? Please explain.
Dec 28 '11 #4
Sorry my english not so well could be make you don't understand want i mean. you can check back my first post #1 line 16 [For RRow = 0 to 5] this is can only print 6 data from my datagrid to my default printer. How to print all data to my printer. This is my question?
Dec 28 '11 #5
Killer42
8,435 Expert 8TB
Can't you apply the same technique used in line 18, but using Rows.Count instead of Columns.Count?
Dec 28 '11 #6
NeoPa
32,556 Expert Mod 16PB
Thread moved from the Insights forum to the Answers forum. Please be more careful in future where you post your questions to (This is certainly not an Insight).
Dec 28 '11 #7
Sorry noted NeoPa,When i changed Columns.Count to Rows.Count i got this error msg: Compile error:invalid qualifer
Dec 28 '11 #8
Killer42
8,435 Expert 8TB
Damn, how do you determine the number of rows (or should that be "records") in a datagrid? I haven't worked with them in years.

Anyone?
Dec 29 '11 #9
Guido Geurs
767 Expert 512MB
this is how to collect data from a datagrid

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. '§ add reference= Microsoft ActiveX Data Object 2.8 Library
  3. '§ C:\Program Files\Common Files\system\ado\msado15.dll
  4.  
  5. Dim ADO_RECSET As ADODB.Recordset '§ Create a Recordset
  6.  
  7. Private Sub Form_Load()
  8.    Set ADO_RECSET = New ADODB.Recordset
  9.    ADO_RECSET.CursorLocation = adUseClient
  10.    ' Add columns to the Recordset
  11.    ADO_RECSET.Fields.Append "Key", adInteger
  12.    ADO_RECSET.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
  13.    ADO_RECSET.Fields.Append "Field2", adDate
  14.    ' Open the Recordset
  15.    ADO_RECSET.Open , , adOpenStatic, adLockBatchOptimistic
  16.    ' Add data to the Recordset
  17.    ADO_RECSET.AddNew Array("Key", "Field1", "Field2"), _
  18.       Array(1, "string1", Date)
  19.    ADO_RECSET.AddNew Array("Key", "Field1", "Field2"), _
  20.       Array(2, "string2", #1/1/2000#)
  21.    ' Populate the Data in the DataGrid
  22.    Set DataGrid1.DataSource = ADO_RECSET
  23. End Sub
  24.  
  25. Private Sub ComPrint_Click()
  26. Dim FIELDSidx As Integer
  27. Dim ITEMidx As Integer
  28. Dim DATA As String
  29.    ADO_RECSET.MoveFirst
  30.    Do Until ADO_RECSET.EOF = True
  31.       DATA = DATA & vbCrLf
  32.       For ITEMidx = 0 To ADO_RECSET.Fields.Count - 1
  33.          DATA = DATA & ADO_RECSET.Fields.Item(ITEMidx).Value & " - "
  34.       Next
  35.       ADO_RECSET.MoveNext
  36.    Loop
  37.    Text1.Text = DATA
  38. End Sub
  39.  
Instead of putting the data in the textbox, send it to the printer.
Jan 1 '12 #10
Killer42
8,435 Expert 8TB
Seems as though the whole recordset creation thing is rather clouding the issue here.

If I'm not mistaken, the point you're making is that there is no record count, and one must simply loop through all the records. Correct?
Jan 2 '12 #11
Guido Geurs
767 Expert 512MB
Yes, there are different types of grids in VB but for the datagrid like in your call, the way to read the records is to go to the first one, read it, go to the next one, ... until EOF. (see demo attached)
Attached Files
File Type: zip how to print all data from datagrid to printer_v1.zip (2.8 KB, 940 views)
Jan 2 '12 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Spire | last post by:
Does anyone know how to print on POS printer (on com port) from C# (other than using dos command type x.txt>com1)? I have attempted with this but nothing happens IntPtr ptr= CreateFile("COM1",...
1
by: Paresh | last post by:
Hi I need to Print asp:datagrid with formatting, which will avoid my writing of crystal reports and can directly print with click of a button. any kind of information is appreciated Thanks...
1
by: Paresh | last post by:
Hi I need to Print asp:datagrid with formatting, which will avoid my writing of crystal reports and can directly print with click of a button. I do not just want to print the current page, I...
2
by: Mitul | last post by:
Hello friends, I am getting stuck at a point in my project. I would like to give functionality of print data from site. but there is a problem is that if there are lots of data which takes...
1
by: ranu s | last post by:
M trying to print image by calling print api (web based application ) As my knowledge is concerned aspnet account wont provide access to netwrk printers ....... My questn is 1)How to print...
1
hariharanmca
by: hariharanmca | last post by:
any know how to Print data through Store Procedure to the printer Directly
3
by: printline | last post by:
Hello Guys I cannot print from a locally installed printer that is mapped to a windows 2003 sever. I have installed the printer locally and can print locally. I connect to the windows 2003...
1
by: vicky87.eie | last post by:
I need to print the image i have drawn in a picture box. My program is create an application similar to paint in windows, I used picture box as the area to draw. Now after completing the work i...
1
by: =?Utf-8?B?SmJhcmJlcg==?= | last post by:
All users in my XP Professional PC were able to print to a network printer until now. Now, the only account that can print to the network printer is the admin account. I have an HP PSC 2200 series...
0
by: Zulqarnain | last post by:
I have developed a report in developer 6i. It properly prints on laser printer but it do not print on receipt printer (CZERLOP). Printing job has sent to printer & printer also detect this job but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.