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

Status
Not open for further replies.

prrm333

Programmer
Apr 14, 2003
97
US
I have the basics working for print preview for records in a database. However I can't get the code working for printing if there is more than one page of records. The following is what I am using which returns one page that is cut off at the bottom and not on the next page:

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;
}
int totalRec = m_dtContacts.Rows.Count;
int index;

for (index = 0; index < totalRec; index++)
{
if (index == totalRec - 1)
{
lCount = 1;
e.HasMorePages = true;
//break;
DataRow row = m_dtContacts.Rows[index];

}
}
m_cnADONetConnection.Close();
}

It goes into an endless loop creating page that when I cancel it just shows the one page cut off at the bottom.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top