Instead of using a PrintPreview you can
A) Take a Direct Print Screen of the DataGrid and Save it as JPG
Quote:
Dim bt As New Bitmap(DataGridView1.Width, DataGridView1.Height)
Dim gr As Graphics = Graphics.FromImage(bt)
bt.Save("D:\Demot.jpg")
|
Or
B) Export the DataGridView Directly to a CSV Format or Text Format
Quote:
Dim strW As New StreamWriter(SaveFileDialog1.FileName)
strW.WriteLine("Sr,Name,Phone Number,Email ID,Date of Birth")
For i As Integer = 0 To DataGridView1.Rows.Count - 1
strW.WriteLine(String.Format("{0},{1},{2},{3},{4}" , i + 1, DataGridView1.Rows(i).Cells(1).Value, DataGridView1.Rows(i).Cells(2).Value, DataGridView1.Rows(i).Cells(3).Value, DateTime.Parse(DataGridView1.Rows(i).Cells(4).Valu e).ToString("dd-MMM-yyyy")))
Next
strW.Close()
|
Please note
The 2nd Line defines the Columns you want..
Quote:
|
strW.WriteLine("Sr,Name,Phone Number,Email ID,Date of Birth")
|
|