my app has a DataGridView where all selected files get listed and added to a class which is the datasource of the DGV.
public partial class Form1 : Form
{
BindingList<Datei> dateienList = new BindingList<Datei>();
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Word(*.docx)| *.docx|PPT(*.pptx)|*.pptx|PDF(*.pdf)|*.pdf|Alle Dateien(*.*)|*.*";//filter is an attribute
ofd.Multiselect = true;
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) //the next code executes only if ok is clicked
{
foreach (String path in ofd.FileNames)
{
Datei datei = new Datei();
datei.filePath = path;
datei.Dateiname = Path.GetFileName(path);
dateienList.Add(datei);
}
}
}
}
datasource class:
public class Datei
{
[DisplayName("Dateiname")]
public string Dateiname { get; set; }
[DisplayName("Neue Dateiname")]
public string NeueDateiname { get; set; }
public string filePath { get; set; }
public string newFilePath { get; set; }
}
I want to make a button to print out all the documents on the list. This is what I tried:
private void button2_Click(object sender, EventArgs e)
{
PrintDialog printDialog1 = new PrintDialog();
PrintDocument printDocument = new PrintDocument();
printDialog1.AllowSelection = true;
printDialog1.AllowSomePages = true;
printDialog1.AllowCurrentPage = true;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
foreach (Datei datei in dateienList)
{
printDocument.Print(); // guess it is totally wrong...
}
}
}
It did not work as expected, printing out blank. Any help is appreciated.
I couldn't avoid opening Word program, but at least it works.