Abhilash J A

Abhilash J A

  • 533
  • 2.4k
  • 597.9k

How can print all images through listview select ?

Jan 4 2017 1:31 PM
Hello Everyone,
 
How can I select all images through select checkbox from listview then click on button. I have find code from google then used inside button click, 
  1.  private void chkbtn_click(object sender, MouseButtonEventArgs e)    
  2.        {    
  3.             if (objTble_Documents.Count() != 0)    
  4.             {    
  5.                try    
  6.                {    
  7.                    PrintDocument pd = new PrintDocument();    
  8.                    pd.PrintPage += new PrintPageEventHandler(PrintPage);    
  9.                    System.Windows.Forms.PrintDialog pdi = new System.Windows.Forms.PrintDialog();    
  10.                    pdi.Document = pd;    
  11.                    if (pdi.ShowDialog() == System.Windows.Forms.DialogResult.OK)    
  12.                    {    
  13.                         pd.Print();    
  14.                    }    
  15.                    else    
  16.                    {    
  17.                        MessageBox.Show("Print Cancelled");    
  18.                    }    
  19.                }    
  20.                catch (Exception ex)    
  21.                {    
  22.                    MessageBox.Show(ex.Message);    
  23.                }    
  24.     }  
  25. }  
 
After applied this code,
 
  1. private void PrintPage(object o, PrintPageEventArgs e)  
  2.      {  
  3.          List<ListViewItemsData> objListViewItemsData = new List<ListViewItemsData>();  
  4.          DMSBusinessLayer service = new DMSBusinessLayer();  
  5.          List<DocumentsUser> objTble_Documents = new List<DocumentsUser>();  
  6.          int UserId = 0;  
  7.          string ImgName = string.Empty;  
  8.          foreach (DocumentsUser item in listView1.SelectedItems)  
  9.          {  
  10.              UserId = Convert.ToInt32(item.UserId);  
  11.              ImgName = item.Parent_File_Name;  
  12.              objTble_Documents = service.PrintUserDocuments(ImgName, UserId).AsEnumerable().Select(m => new DocumentsUser()  
  13.              {  
  14.                  Child_File_Name = m.Field<string>("Child_File_Name"),  
  15.                  FilePath = m.Field<string>("FilePath"),  
  16.                  Parent_File_Name = m.Field<string>("Parent_File_Name")  
  17.              }).ToList();  
  18.          }  
  19.   
  20.          foreach (var i in objTble_Documents)  
  21.          {  
  22.              objListViewItemsData.Add(new ListViewItemsData()  
  23.              {  
  24.                  GridViewColumnName_ImageSource = (Convert.ToString(i.FilePath) + Convert.ToString(i.Parent_File_Name) + "_" + Convert.ToString(i.Child_File_Name)),  
  25.              });  
  26.          }  
  27.   
  28.          foreach (var ii in objListViewItemsData)  
  29.          {  
  30.              System.Drawing.Image img = System.Drawing.Image.FromFile(ii.GridViewColumnName_ImageSource.ToString());  
  31.              System.Drawing.Rectangle m = e.MarginBounds;  
  32.   
  33.              if ((double)img.Width / (double)img.Height > (double)m.Width / (double)m.Height)  
  34.              {  
  35.                  m.Height = (int)((double)img.Height / (double)img.Width * (double)m.Width);  
  36.              }  
  37.              else  
  38.              {  
  39.                  m.Width = (int)((double)img.Width / (double)img.Height * (double)m.Height);  
  40.              }  
  41.              e.Graphics.DrawImage(img, m);  
  42.          }  
  43.      }  
 But run this much of code, printing only one image, that last image from the loop. How can I solve this issue? Please help me...
 

Answers (1)