How to show data table on print document in place of print document

  • Thread starter Thread starter engahmedbarbary
  • Start date Start date
E

engahmedbarbary

Guest
Problem

I need to show data table below on print document in place of datagridview

data table i need to show on print document is dtGetChecked

the main purpose from that i need to show data on print preview and not allow user or client from print

dtGetChecked = GetChecked();

int i=0;
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
int width = 0;
int height = 0;
int x = 0;
int y = 0;
int rowheight = 0;
int columnwidth = 0;

StringFormat str = new StringFormat();
str.Alignment = StringAlignment.Near;
str.LineAlignment = StringAlignment.Center;
str.Trimming = StringTrimming.EllipsisCharacter;
Pen p = new Pen(Color.Black, 2.5f);
//e.Graphics.DrawRectangle(p,dataGridView1.Bounds);

//printPreviewDialog1.Document=printDocument1;
//e.Graphics.DrawString("Hi this a test print", new Font(Font.SystemFontName,10.5f), Brushes.Black, new PointF(250.0f, 250.0f));
//e.Graphics.DrawImage((Image)bm,new Point(10,10));

#region Draw Column 1

e.Graphics.FillRectangle(Brushes.LightGray, new Rectangle(100, 100, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height));
e.Graphics.DrawRectangle(Pens.Black, 100, 100, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height);
e.Graphics.DrawString(GridFooter.Columns[0].HeaderText, GridFooter.Font, Brushes.Black, new RectangleF(100, 100, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height), str);

#endregion

#region Draw column 2

e.Graphics.FillRectangle(Brushes.LightGray, new Rectangle(100 + GridFooter.Columns[0].Width, 100, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height));
e.Graphics.DrawRectangle(Pens.Black, 100 + GridFooter.Columns[0].Width, 100, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height);
e.Graphics.DrawString(GridFooter.Columns[1].HeaderText, GridFooter.Font, Brushes.Black, new RectangleF(100 + GridFooter.Columns[0].Width, 100, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height), str);

width = 100 + GridFooter.Columns[0].Width;
height = 100;
//variable i is declared at class level to preserve the value of i if e.hasmorepages is true
while (i < GridFooter.Rows.Count)
{
if (height > e.MarginBounds.Height)
{
height = 100;
width = 100;
e.HasMorePages = true;
return;
}

height += GridFooter.Rows.Height;
e.Graphics.DrawRectangle(Pens.Black, 100, height, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height);
e.Graphics.DrawString(GridFooter.Rows.Cells[0].FormattedValue.ToString(), GridFooter.Font, Brushes.Black, new RectangleF(100, height, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height), str);

e.Graphics.DrawRectangle(Pens.Black, 100 + GridFooter.Columns[0].Width, height, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height);
e.Graphics.DrawString(GridFooter.Rows.Cells[1].Value.ToString(), GridFooter.Font, Brushes.Black, new RectangleF(100 + GridFooter.Columns[0].Width, height, GridFooter.Columns[0].Width, GridFooter.Rows[0].Height), str);

width += GridFooter.Columns[0].Width;
i++;
}
}



string sql= select MemberCode,SpecialCode,Name,MemberImage from members

DataTable dtDisplayDataPayment= DataAccess.ExecuteDataTable(sql);
public DataTable GetChecked()
{
DataTable table = new DataTable();
table.Columns.Add("MemberCode", typeof(string));
table.Columns.Add("MemberImage", typeof(Byte[]))));









for (int i = 0; i < dtDisplayDataPayment.Rows.Count; i++)
{

bool Ischecked = Convert.ToBoolean(GridFooter.Rows.Cells["PrintFlag"].Value);
if (Ischecked == true)
{
DataRow newRow = table.NewRow();
newRow["MemberCode"] = Utilities.ObjectConverter.ConvertToString(dtDisplayDataPayment.Rows["MemberCode"]);
newRow["MemberImage"] = dtDisplayDataPayment.Rows["MemberImage"];

table.Rows.Add(newRow);
}
}

return table;


}

Continue reading...
 
Back
Top