Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
hello,
i need some help here.. I don't know how to do this,,
i have form contains datagridview and i want to print (to a paper) an image from the datagridview,
and i need to get the image data from Current Row that i clicked. Can someone help please?
here is the code i've been trying
C#
private void PrintDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            byte[] gambar = new byte[0];
            gambar = (byte[])(dgv_ProductData.CurrentRow.Cells[5].Value);
            MemoryStream ms = new MemoryStream(gambar);
            Size sz = new Size();
            Bitmap bm = new Bitmap(ms);
            e.Graphics.DrawImage(bm, 0, 0);
        }

        private void btn_Print_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }
Posted
Updated 13-Jun-13 21:10pm
v2
Comments
Sunasara Imdadhusen 13-Jun-13 7:50am    
What you tried??
Sam Oryza Reyno 13-Jun-13 21:57pm    
i've tried to Show the picture from data grid in other form, and then print the form in case i didn't know how to do what i wanted.. but printing the Form made the printing result bad, i mean it isn't good looking for people..
Sunasara Imdadhusen 14-Jun-13 3:09am    
do not post your code inside the comment box. pls use update question option
Sam Oryza Reyno 14-Jun-13 3:31am    
i'm sorry,, newb here..
so can u help me maybe?
BulletVictim 14-Jun-13 4:09am    
Take a look at the following. Its not exactly what you want but this might help somewhat to get you to where you want to go.
https://www.dropbox.com/s/dzfstpm8c7i1tgq/PrintDGV.cs

Or take a look at one of these:
http://www.codeproject.com/Articles/16670/DataGridView-Printing-by-Selecting-Columns-and-Row

http://www.codeproject.com/Articles/18042/Another-DataGridView-Printer

http://www.codeproject.com/Articles/28046/Printing-of-DataGridView

1 solution

ahh,, its my stupid mistake,, i accidently delete my handler.. Sorry guys

C#
private void PrintDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    byte[] gambar = new byte[0];
    gambar = (byte[])(dgv_ProductData.CurrentRow.Cells[5].Value);
    MemoryStream ms = new MemoryStream(gambar);
    Bitmap bm = new Bitmap(ms);
    e.Graphics.DrawImage(bm, 0, 0);
}

private void btn_Print_Click(object sender, EventArgs e)
{
    printPreviewDialog1.Document = printDocument1;
    printPreviewDialog1.ShowDialog();
    printDialog1.ShowDialog();
}
 
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