Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Preview and HasMorePages

Status
Not open for further replies.

prrm333

Programmer
Apr 14, 2003
97
US
I'm calling the following from a command button to print preview records from an Access DB. It works except it doesn't handle more than one page. It previews the one page and nothing for the remaining pages or records.

void docPrintPage(object sender, PrintPageEventArgs e)
{
e.HasMorePages = false;
e.Graphics.DrawLine(new Pen(Color.Black, 2), 60, 90, 720,
90);
string strDisplay = "Contact Phone List";
System.Drawing.Font fntString = new Font("Arial", 18,
FontStyle.Bold);
e.Graphics.DrawString(strDisplay, fntString,
Brushes.Black, 80, 100);
e.Graphics.DrawLine(new Pen(Color.Black, 2), 60, 140, 720,
140);
fntString = new System.Drawing.Font("Courier", 10,
FontStyle.Bold);
e.Graphics.DrawString("Name" + "\t\t\t\t\t" + "Home Phone"
+ "\t\t" + "Fax Phone", fntString, Brushes.Black, 80,
150);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 180, 720,
180);
m_cnADONetConnection.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=contacts.mdb";
m_cnADONetConnection.Open();
string sqlText = "Select * From Contacts order by
[LastName],[FirstName]";
m_daDataAdapter = new OleDbDataAdapter(sqlText,
m_cnADONetConnection);
OleDbCommandBuilder m_cbCommandBuilder =
new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtContacts);
DataSet dtSet = new DataSet();
m_daDataAdapter.Fill(dtSet, "Contacts");
DataTable dTable = dtSet.Tables[0];
int rPos = 200;
int lCount = 0;
foreach (DataRow dtRow in dTable.Rows)
{
string fName = dtRow["LastName"] + ", " + dtRow
["FirstName"].ToString().PadRight(10) + "\t\t\t" +
dtRow["HPhone"].ToString().PadRight(10) + "\t\t" +
dtRow["FPhone"];
fntString = new Font("Courier New", 10, FontStyle.Bold);
e.Graphics.DrawString(fName, fntString, Brushes.Black, 80,
rPos);
rPos = rPos + 40;
lCount++;
if (lCount == 20)
{
e.HasMorePages = true;
lCount = 0;
}
else
{
e.HasMorePages = false;
}
}
m_cnADONetConnection.Close();
}
}
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top