Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

Filtered datagridview data print with print document. sql Data table with c#
dear sir,
it is not working.
Should I use a models for that?
So how do I connect a data grid to a models?
could you please to help me..
i used below codes..(with out models)

*).DataTable dtdata = new DataTable();

*).adapter = new SqlDataAdapter("SELECT * FROM dbo.data", connection);
adapter.Fill(dtdata);
*).(dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("txt1 like '%" + txt1.Text + "%'");
*).e.Graphics.DrawString(datafind[i].Txt.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(150, 200));

What I have tried:

e.Graphics.DrawString(datafind[i].Txt.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(150, 200));
Posted
Updated 31-Jul-21 18:27pm
v3
Comments
Richard MacCutchan 1-Aug-21 3:20am    
Use the debugger to check exactly what is happening when you run your code. Without the actual data we cannot guess why it is wrong.
Member 15225191 1-Aug-21 11:22am    
Dear sir,
Richard MacCutchan,
I did not write the full code as it is not allowed here. If you allow me to publish the full code, I would like to publish it.
Let me know a way to write it down for you
Richard MacCutchan 1-Aug-21 11:38am    
Thank you, but you still need to gather some proper details to find out what the problem is. Remember we have never seen this code before and we certainly have no idea what is meant by you writing, "it is not working."
Member 15225191 1-Aug-21 11:59am    
Thank you,
I want to enter the filter data in the print document in the data grid. I would like to re-enter the code I wrote in the print document as follows.
The problem I have is that it doesn’t happen.
I thank you very much.

e.Graphics.DrawString(datafind[i].Txt.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(150, 200));
Member 15225191 1-Aug-21 11:13am    
private void QPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("custom", 1652, 1169);
pd.DefaultPageSettings.Landscape = true;

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