|
|
Comments and Discussions
|
|
 |

|
Absolutely love this software; but I cannot change RowHeight to CellHeight at run time; Have tried:
printer = new DGVPrinter();
printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.PrintColumnHeaders = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.FooterSpacing = 15;
printer.RowHeight = printer.RowHeightSetting.CellHeight;
printer.RowHeight = RowHeightSetting.CellHeight;
printer.RowHeight = printer.CellHeight;
I have tried even more combinations but all yield compile errors. I have tried Google. As a last resort, I created DGVPrinter.dll and DGVPrinter2.dll and changed the default setting for RowHeight but it sure would be nice to only have to use one DLL.
Just a simple example of `printer.` for RowHeight ??
If anyone is in a really generous mood, a simple example of `printer.` for printing in the center of the page ??
Thank you in advance for your time and consideration.
Regards
Ed Sharp
ed-sharp@usa.net
|
|
|
|

|
Sorry for the delayed reply. I think what you want is:
print.RowHeight = DGVPrinter.RowHeightSetting.CellHeight;
Let me know if this helps ...
Steve G.
|
|
|
|

|
Can anyone see my entry dated the 27/12/2012. I have not seen any response to that entry.
regards Ron.
|
|
|
|

|
I had, and had thought I'd emailed you about it - however, I can't find the outgoing email. Perhaps my memory isn't what it used to be? Anyway, I'm on vacation at the moment. I'll look into this when I return. Thanks for reminding me about this one!
Steve G.
|
|
|
|

|
Hi Steve,
I have a DGV that for some columns containing numeric data I have the defaultcellstyle.alignment set to MiddleRight and the defaultcellstyle.padding set to e.g. 0,0,10,0 (padding to right of value only). This appears to cause DGVPrinter to draw the right border for that column nearer the cell value rather than drawing the right border in its correct place taking into account the padding applied to the cell value.
e.g. given three cells of which the middle one is the right-justified padded one:
Should be drawn as: | xxxx| 1234 |xxxx
is in fact drawn as: | xxxx| 1234| |xxxx
Any ideas?
Cheers
Derek
modified 10 Apr '13 - 13:56.
|
|
|
|

|
That sounds very much like a bug. I'm on vacation and will take a look at things when I return. Thanks for reporting this!
Steve G.
|
|
|
|

|
Thank you very much for such a SIMPLE and EASY article for printing GRIDVIEW....
I was searching for this very desperately, but all I found very complex codes, I used them, but there were some part of code snippet unexplained, making it hard to use.
But your code was very simple to implement...THANKS A LOT!
|
|
|
|

|
Just wanted to drop a few lines to thank the author for this excellent piece of code! It is well thought out and easy to implement. Again, many many thanks!
|
|
|
|

|
It's great works excellent and too easy to use
|
|
|
|

|
First, Let me say that I'm sure that this is the best DataGridView Printer ever made.
I just need some help concerning drawing text inside headers with a 270 angle. Apparently I'm not able to subscribe to the OwnerDraw event. What does this mean? print.OwnerDraw += new CellOwnerDrawEventHandler(print_OwnerDraw). Is there anything missing?
|
|
|
|

|
First, my apologies for not responding sooner - I've just discovered that some of the post emails from CodeProject are going into my junk folder!
To answer your question, the statement you list there registers a handler for the OwnerDraw event. The argument "print_OwnerDraw" is actually the name of a procedure that will get called when the OwnerDraw event is triggered. You write this routine. The code in this routine is your opportunity to do what you need to to handle the OwnerDraw event. I'd strongly suggest you search the internet for help on handling events - there's lots of examples out there to help you wire up the event handler properly.
Good Luck,
Steve G.
|
|
|
|

|
Currently when the row header is printed the Row Style is used as in
//-----------------------------------------------------------------
// Print Row background
//-----------------------------------------------------------------
// get current row style, start with header style
DataGridViewCellStyle rowstyle = row.InheritedStyle.Clone();
Should rowstyle not be defined as
DataGridViewCellStyle rowstyle = row.HeaderCell.InheritedStyle.Clone();
The row headers will then have the same look as the datagridcview.
regards ron
|
|
|
|

|
Good catch, but actually, the change needs to be made in the code just below there - where the header cell is printed.
Thanks, I've added this to the list of fixes for the next release.
Steve G.
|
|
|
|

|
I have 3 suggestion.
1. can u add some custom row in a doc end? for display the total price, percentage as well as some tips. before i think add this to DataGridView and print, but when print is finish , i should clear that row. if i can add multiple DataGridView, and you combine this ? , it's so easy for me.
2.is there any way can let the column width automatically populated? if i'm use DGVPrinter.ColumnWidthSetting.CellWidth or DGVPrinter.ColumnWidthSetting.Porportional Its width may exceed the page, if i'm use ColumnWidthSetting.DataWidth It will be remaining lot of space. can u just let It automatically calculates the width to fit the page? (Beyond the automatic line feed)?
3.if i'm print , i only can print vertical mode on A4. can i choise the print mode like horizontal?
very thanks.
|
|
|
|

|
Excellent piece of work. It only takes a small change to make it compatible back to Dot Net 2.0. Online conversion from C# to VB.net also worked cleanly.
|
|
|
|

|
Does anyone have a VB.NET conversion?
|
|
|
|

|
Hi,
I need to make my own print preview page to use a Ribbon Control like in Paint and show the print preview not in a new dialog form.
Here my code:
Private Sub PT_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PT.PrintPage
Dim printer = New DGVPrinter()
Dim prflex As DataGridView
prflex = XpTabControl1.SelectedTab.Controls(0)
printer.RowHeight = DGVPrinter.RowHeightSetting.CellHeight
printer.EmbeddedPrint(prflex, e.Graphics, New Rectangle(10, 10, prflex.Width, prflex.Height))
End Sub
After this I set
PrintPreviewControl1.Document = PT
I have problems to translate the Embedded Printing Process for Multipage Printing C# code to VB.net, anybody just used this feature in VB?
Here a link to my print preview
https://dl.dropbox.com/u/39631349/preview_Another%20DataGridView%20Printer.png[^]
Thanks, Thomas
|
|
|
|

|
When the datagridview is wider than a printed page and the RowHeight setting is CellHeight then printing is fine irrespective of 'porportional' setting.
But when RowHeight is set to DataHeight then the height of the rows seems to depend upon the largest text string within that row even though the text is not wrapped.
regards ron.
further to the problem above
the problem seems to be the connection between AdjustPageSets and RecalcRowHeights. the routine AdjustPagesets is entered with a pageset which calls RecalcRowHeights with the number of columns within that pageset. On further pagesets RecalcRowHeights starts off looking at columns within the first pageset and because the column widths are different the heights of the rows are adjusted even though data in cells is not wrapped.
In the routine calccellsize after the else statement I put in a mod because a checkboxcell returns an invalid height when g.MeasureString(String,Font,Size,format) is used, at least it does on my system.
else
{
if (cell is DataGridViewColumnHeaderCell)
datasize = g.MeasureString(cell.OwningColumn.HeaderText.ToString(), cellstyle.Font,
new SizeF(basewidth, maxPages), format);
else
{
if ("DataGridViewCheckBoxCell" == dgv.Columns[cell.ColumnIndex].CellType.Name)
datasize = g.MeasureString(cell.EditedFormattedValue.ToString(), cellstyle.Font);
else
datasize = g.MeasureString(cell.EditedFormattedValue.ToString(), cellstyle.Font,
new SizeF(basewidth, maxPages), format);
}
// if we have excessively large cell, limit it to one page width
if (printWidth < datasize.Width)
datasize = g.MeasureString(cell.FormattedValue.ToString(), cellstyle.Font,
new SizeF(pageWidth - cellstyle.Padding.Left - cellstyle.Padding.Right, maxPages),
format);
}
happy new year readers
further to the problem between AdgustPageSets and RecalcRowHeights i put in a mod
int prevColCount = 0;
for (i = 0; i < pagesets.Count; i++)
{
AdjustPageSets(g, pagesets[i], prevColCount);
prevColCount += pagesets[i].colwidths.Count;
}
and within AdjustPageSets
private void AdjustPageSets(Graphics g, PageDef pageset, int prevcolCount)
{
.
.
RecalcRowHeights(g, i + prevcolCount, pageset.colwidths[i]);
.
}
this rough and ready mod fixed the problem of rowheights along with the calccellsize.
regards Ron
modified 2 Jan '13 - 9:40.
|
|
|
|
|

|
I'm trying to recreate the issue you found I'm not sure I'm following you. Are you saying that when you hid the first column, that all the row headers were not displayed?
-- Edit --
After a bit of poking about, I've found the issue. It will be fixed in the next update. Thanks for reporting this!
-- Edit --
Thanks,
Steve G.
modified 24 Dec '12 - 13:43.
|
|
|
|
|

|
Good work! But code formating...
|
|
|
|

|
My code is perfectly formatted ... for me.
Seriously, thanks for the good vote.
|
|
|
|

|
Throws exceprion "Argument out of range..." in:
calccellsize(g, col.HeaderCell, i, headercolstyle, usewidth, columnheadercellformat);
call, when trying get property cell.EditedFormattedValue.
MSDN, says:
Exception Condition
ArgumentOutOfRangeException The row containing the cell is a shared row.
-or-
The cell is a column header cell.
Why, then, this is not happening all the time, but only from a specific table?
|
|
|
|

|
The problem was solved in this way:
if (cell is DataGridViewColumnHeaderCell)
datasize = g.MeasureString(cell.OwningColumn.HeaderText.ToString(),cellstyle.Font,
new SizeF(basewidth, maxPages), format);
else
datasize = g.MeasureString(cell.EditedFormattedValue.ToString(), cellstyle.Font,
new SizeF(basewidth, maxPages), format);
And so in all the places where you are trying to get EditedFormattedValue.
Also further found another bug:
CheckBoxState state = (checkboxcell.Value == null || (Boolean)checkboxcell.Value == false) ?
CheckBoxState.UncheckedNormal : CheckBoxState.CheckedNormal;
Skipped check for DBNull. After change:
CheckBoxState state = (checkboxcell.Value == null || checkboxcell.Value == DBNull.Value || (Boolean)checkboxcell.Value == false) ?
CheckBoxState.UncheckedNormal : CheckBoxState.CheckedNormal;
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
DataGridView printing encapsulated in a stand-alone object. Very easy to use! Updated to allow printing columns wider than one page.
| Type | Article |
| Licence | CPOL |
| First Posted | 16 Mar 2007 |
| Views | 811,271 |
| Downloads | 23,436 |
| Bookmarked | 361 times |
|
|