Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i write code to print the data in datagridview as a report ,this is the code:
C#
 private void timer1_Tick(object sender, EventArgs e)
        {
            string time = DateTime.Now.Hour + ":" + DateTime.Now.Minute
                                        + ":" + DateTime.Now.Second;

            if (time == "23:18:10")
            {
PrintDocument document = new PrintDocument();
                document.PrintPage += this.PrintPage;

         
                    document.Print();
            }}
        
            private void PrintPage(object sender, PrintPageEventArgs e) {
            using(Font font = new Font("Lucida Console",30)){
                e.Graphics.DrawString(@@@ how can i call the data from datagridview@@, 
                    font, 
                    Brushes.Blue,
                    e.PageBounds.Left, 
                    e.PageBounds.Top);
            }
        }

the problem is how can i call the datagridview in that code? see this mark @@@ in that code
Posted
Comments
joshrduncan2012 25-Jun-13 17:29pm    
Do you have an underlying datatable bound to the datagridview?
loai_maane 26-Jun-13 1:34am    
no
[no name] 25-Jun-13 18:20pm    
You do not "call" data from a datagridview. You would need to get the data by going through the datagridview's properties. Or, get the data from the data source.

 
Share this answer
 
Instead of extracting data from DataGrid, you should use the source of DataGrid print the report. See a similar article : Crystal Report with DataSet and DataTable using C#[^]

You can also check:
Build Reports using Crystal Reports and Stored Procedures[^]


--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900