I am using DGVPrinterHelper to print several DataGridViews (DGVs) at once. Currently, for each DGV, I have to open a configuration window that looks like this:
Print options.
The problem with this is that sometimes there is 10 or even more different DGVs and I have to sit there and just spam ‘Print’ till it finally reaches the end.
Is there a way to add all the DGVs to one document with each being its own page and then just print it once or a way to make me not have to go to that window for every DGV.
Here´s the code responsible for this in my application:
private void bttPrint_Click(object sender, EventArgs e)
{
GenerateDataGridViewsForEachFixture();
string partNumbersSubtitle = string.Join(", ", PartNumbers);
foreach (var dataGrid in allDataGrids)
{
string fixtureNumber = dataGrid.Rows[0].Cells[0].Value.ToString();
string lista = PartNumbers[0];
// Configura e imprime o DataGridView
DGVPrinter printer = new DGVPrinter();
printer.Title = "Table: " + fixtureNumber;
printer.SubTitle = "Lists: " + partNumbersSubtitle;
printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.Footer = "Print DGV";
printer.PrintDataGridView(dataGrid);
}
}
private void GenerateDataGridViewsForEachFixture()
{
var orderedFixtureGroups = setData
.GroupBy(data => data.Table)
.ToDictionary(
g => g.Key,
g => g
.GroupBy(sd => sd.PartNumber)
.Select(gp => gp.First())
.OrderBy(sd => int.Parse(sd.Feeder))
.ToList()
);
allDataGrids.Clear();
foreach (var fixtureGroup in orderedFixtureGroups)
{
DataGridView dgv = new DataGridView();
// Define the columns
dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Table" });
dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "TypeFeeder" });
dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Feeder" });
dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Position" });
dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Pup" });
dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "PartNumber" });
dgv.Columns.Add(new DataGridViewCheckBoxColumn { Name = "Missing" });
foreach (var data in fixtureGroup.Value)
{
dgv.Rows.Add(data.Table, data.TipoFeeder, data.Feeder, data.Position, data.Pup, data.PartNumber, false);
}
allDataGrids.Add(dgv);
}
}
Yuri Lucas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1