1
Reply

Not implemented exception was unhandled by user code

arun kumar

arun kumar

Apr 18 2012 5:51 AM
4.8k
i have completed my windows form, but  i can't enable to print page, i have set two button 1.printpreview 2. print button i have entered these code, i have a error in datagridviewprinter.cs file, i am upload my error code and design view i am also entered my code, please help me

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Drawing.Printing;
namespace logins
{
  public partial class monthpur : Form
  {

 
  OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\ARUNKUMAR\\myproject\\myprojects\\data\\as.accdb");
  DataGridViewPrinter MyDataGridViewPrinter;

  OleDbCommand com;
  string str;

  public monthpur()
  {
  InitializeComponent();
  }

  private void textBox1_TextChanged(object sender, EventArgs e)
  {

  }



  private void textBox7_TextChanged(object sender, EventArgs e)
  {



  }

  private void button1_Click(object sender, EventArgs e)
  {
  str = " insert into purmonth (" + "purchasedate," + "paiddate," + "cusid," + "cusname," + "mill," + "item," + "quantity," + "rate," + "debit," + "credit" + " )  values (('" + purchasedateBox1 .Text  + "'),('" + paidBox.Text + "'),('" + cusBox.Text + "'),('" + cusnameBox.Text + "'),('" + millBox.Text + "'), ('" + comboBox1 .SelectedItem + "'),('" + quantityBox.Text +"' ), ('" + rateBox.Text + "' ),('" +  debitBox.Text + "'),('" + creditBox.Text +"' ))";
  //str = " insert into purmonth values (('" + dateTimePicker1.Text + "'),('" + dateTimePicker2.Text + "'),('" + textBox3.Text + "'),('" + textBox4.Text + "'),('" + textBox5.Text + "'), ('" + comboBox1.SelectedItem + "'),('" + quantityBox.Text + "'), ('" + rateBox.Text + "'),('" + textBox7.Text + "'),('" + creditBox.Text + "'))";
  com = new OleDbCommand(str, con);
  com.ExecuteNonQuery();

  MessageBox.Show("Records Successfully Stored");

  // con.Close();

  }


  private void monthpur_Load(object sender, EventArgs e)
  {
  con.Open();

  }

  private void creditBox_TextChanged(object sender, EventArgs e)
  {
  try
  {
  creditBox.Text = (decimal.Parse(quantityBox.Text) * decimal.Parse(rateBox.Text)).ToString();

  }
  catch
  {

  }

  }

  private void totalcredit_TextChanged(object sender, EventArgs e)
  {
 
 

  }

  private void label11_Click(object sender, EventArgs e)
  {

  }

  private void button2_Click(object sender, EventArgs e)
  {
  purchasedateBox1.Text = "";
  paidBox.Text = "";
  cusBox.Text = "";
  cusnameBox.Text = "";
  millBox.Text = "";
  comboBox1.Text = "";
  quantityBox.Text = "";
  rateBox.Text = "";
  debitBox.Text = "";
  creditBox.Text = "";



  }

  private void button3_Click(object sender, EventArgs e)
  {
  string str = "select * from purmonth";

  com = new OleDbCommand(str, con);

  DataSet vds = new DataSet();
  OleDbDataAdapter vda = new OleDbDataAdapter(com);
  vda.Fill(vds, "res");

  dataGridView1.DataSource = vds.Tables["res"];

  vda.Dispose();
  com.Dispose();

  }

  private void button4_Click(object sender, EventArgs e)
  {
 
  int sum = 0;
  for (int i = 0; i < dataGridView1.Rows.Count; ++i)
  {
  sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[9].Value);
  }
  label11.Text = sum.ToString();
  }

  private void button5_Click(object sender, EventArgs e)
  {

  int sum = 0;
  for (int i = 0; i < dataGridView1.Rows.Count; ++i)
  {
  sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[8].Value);
  }
  label12.Text = sum.ToString();
  }

  private void label13_Click(object sender, EventArgs e)
  {
 

  }

  private void button6_Click(object sender, EventArgs e)
  {
  label13.Text = (decimal.Parse(label11.Text) - decimal.Parse(label12.Text)).ToString();

 
  }


  private void MyPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  {
  bool more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics);
  if (more == true)
  e.HasMorePages = true;
  }







  private void button7_Click(object sender, EventArgs e)
  {
  if (setuptheprinting())
  {
  PrintPreviewDialog myprintpreviewdialog = new PrintPreviewDialog();
  myprintpreviewdialog.Document = MyPrintDocument;
  myprintpreviewdialog.ShowDialog();
  }
  }
 
 
 
 
 
 
 
 
  private bool setuptheprinting()
  {
  PrintDialog myprintdialog = new PrintDialog();
  myprintdialog.AllowCurrentPage = true ;
  myprintdialog.AllowPrintToFile = false;
  myprintdialog.AllowSelection = false;
  myprintdialog.AllowSomePages = false;
  myprintdialog.PrintToFile = false;
  myprintdialog.ShowHelp = false;
  myprintdialog.ShowNetwork = false;

  if (myprintdialog.ShowDialog() != DialogResult.OK)
  return false;
  MyPrintDocument.DocumentName = "purmonth";

  MyPrintDocument.PrinterSettings = myprintdialog.PrinterSettings;
  MyPrintDocument.DefaultPageSettings = myprintdialog.PrinterSettings.DefaultPageSettings;
  MyPrintDocument.DefaultPageSettings.Margins = new Margins(40, 40, 40, 40);

  if (MessageBox.Show("Do you want the report to be centered on the page", "InvoiceManager - Center on Page", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)

  MyDataGridViewPrinter = new DataGridViewPrinter(dataGridView1, MyPrintDocument, true, true, "purmonth", new Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);
  else
  MyDataGridViewPrinter = new DataGridViewPrinter(dataGridView1, MyPrintDocument, false, true, "purmonth", new Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);

  return true;


  // throw new NotImplementedException();
  }

  private void button8_Click(object sender, EventArgs e)
  {
  if (setuptheprinting())
  MyPrintDocument.Print();


  }

  /// public System.Drawing.Printing.PrintDocument MyPrintDocument { get; set; }

  //  public object MyDataGridView { get; set; }

  // internal DataGridViewPrinter MyDataGridViewPrinter { get; set; }

  //  private void MyPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
  //  {
  //  bool more =  MyDataGridViewPrinter.DrawDataGridView(e.Graphics);
  //  if (more == true)
  //  e.HasMorePages = true;

  //  }
  }
  }

please check my error image





Attachment: error.rar

Answers (1)