I have a multicolumn listview box. I have looked all around for some basic instructions on how to print its contents and remained baffled.
I would appreciate a the simplest example or url to simple example on how to do this. Should I print the listview box to a text file, then use stream reader
appreciate your help!
david

print contents of multicolumn listview box - arghh!
Sharezxx
Looks like some of the code got jumbled on my cut and paste...
Code should read...
printableListView.Columns.Add("Column 3", 100, HorizontalAlignment.Left);
// Wrap results. If multiple entries in Result column, then they are separated by a ";".
NOT
printableListView.Columns.Add("Column 3", 100, HorizontalAlignment.Left);
}
// Wrap results. If multiple entries in Result column, then they are separated by a ";".
IreneSmith
mario.muja
Jon Abbott
Hey David,
I just had a similar problem, and I was able to print the contents of a listView by using this example:
http://www.codeproject.com/cs/miscctrl/PrintableListView.asp
The irritating thing with printing listViews is with Cell Wrapping since the List View does not allow multiple lines or text wrapping. To get around this cell wrapping problem, just insert "\n" into the text string in relevant places such as every 40 characters, etc.
Here's some code...
private void buttonPrint_Click(object sender, EventArgs e)
{
PrintableListView printableListView = new PrintableListView();
printableListView.Columns.Add("Column 1", 100, HorizontalAlignment.Left);
printableListView.Columns.Add("Column 2", 100, HorizontalAlignment.Left);
printableListView.Columns.Add("Column 3", 100, HorizontalAlignment.Left);
}
// Wrap results. If multiple entries in Result column, then they are separated by a ";".
foreach (ListViewItem lvi in this.listViewAlertHistory.Items)
{
string lviResults = "";
string[] results = lvi.SubItems[2].Text.Split(';');
if(results.Length > 1)
{
foreach(string result in results)
{
lviResults = lviResults + result.Trim() + "\n";
}
}
else
{
lviResults = lvi.SubItems[2].Text.Trim();
}
ListViewItem aItem = new ListViewItem();
aItem.SubItems[0].Text = lvi.SubItems[0].Text;
aItem.SubItems.Add(lvi.SubItems[1].Text);
aItem.SubItems.Add(lviResults);
printableListView.Items.Add(aItem);
}
printableListView.Title = "Alert History Results";
printableListView.FitToPage = true;
printableListView.PrintPreview();
// To print...
// printableListView.Print();
}