In lstresult i put in the item name. in lstresult2 i put in the the numerical value for that item. i included a picture to show what i mean. I want to alphabetize lstResult but i want the value in lstResult2 to stay with the value. A better example is included in the picture.
Also how do you print lstResult and lstResult2 side by side like i have it in the picture i already put in the code for lstResult but i dont know how to get lstresult 2 to appear next to it. This is the code i have for that so far:
private int nextItem = 0;
private void docPrint_PrintPage(object sender, PrintPageEventArgs e)
{
float linesPerPage = 0;
float yPos = 0;
float xPos = 0;
int count = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
string line = null;
m_objFont = new Font("Arial", 12);
// Calculate the number of lines per page.
linesPerPage = e.MarginBounds.Height /
m_objFont.GetHeight(e.Graphics);
// Print each line of the file.
foreach (Control objControl in this.Controls)
{
if (objControl.GetType().Name != "Button" && objControl.GetType().Name != "MenuStrip" && objControl.Name != "lblItemName" && objControl.Name != "lblItemValue" )
{
line = objControl.Text;
switch (objControl.Name)
{
case "lblSum":
e.Graphics.DrawRectangle(Pens.Black, lblSum.Location.X + leftMargin, lblSum.Location.Y + topMargin - 4, lblSum.Width, lblSum.Height);
m_objFont = objControl.Font;
break;
default:
m_objFont = objControl.Font;
m_objFont = new Font("Arial", 12);
break;
}
xPos = leftMargin + objControl.Location.X;
yPos = topMargin + objControl.Location.Y;
e.Graphics.DrawString(line, m_objFont, Brushes.Black, xPos, yPos);
}
}
while (count < linesPerPage && nextItem < lstResult.Items.Count)
{
m_objFont = new Font("Arial", 12, FontStyle.Underline);
yPos = topMargin + 195 + (count *
m_objFont.GetHeight(e.Graphics));
line = lstResult.Items[nextItem].ToString();
e.Graphics.DrawString(line, m_objFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
nextItem++;
}
// If more lines exist, print another page.
if (nextItem < lstResult.Items.Count - 1)
e.HasMorePages = true;
else
{
e.HasMorePages = false;
nextItem = 0;
}
}
private void mnuFilePrint_Click(object sender, EventArgs e)
{
PrintDocument docPrint = new PrintDocument();
docPrint.PrintPage += new PrintPageEventHandler(docPrint_PrintPage);
if (PrinterSettings.InstalledPrinters.Count == 0)
{
ErrorMessage();
return;
}
docPrint.Print();
}
private void mnuFilePrintPreview_Click(object sender, EventArgs e)
{
PrintDocument docPrint = new PrintDocument();
docPrint.PrintPage += new PrintPageEventHandler(docPrint_PrintPage);
if (PrinterSettings.InstalledPrinters.Count == 0)
{
ErrorMessage();
return;
}
objPreview.Document = docPrint;
objPreview.ShowDialog();
}
void ErrorMessage()
{
MessageBox.Show("No printers istalled. You must" + "have a printer installed to preview or print" + "the document.", "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Any help would be appreciated to either or both of the questions. Thank You!