|
|
Comments and Discussions
|
|
 |

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

|
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.
|
|
|
|

|
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?
|
|
|
|

|
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
|
|
|
|

|
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?
|
|
|
|

|
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.
|
|
|
|
|

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

|
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?
|
|
|
|

|
Nice program but have encounted two problems.
1. CheckBoxState state = (checkboxcell.Value == null || (Boolean)checkboxcell.Value == false) ? CheckBoxState.UncheckedNormal : CheckBoxState.CheckedNormal;
gives exception below
System.InvalidCastException was unhandled by user code
Message=Specified cast is not valid.
replaced statement with
CheckBoxState state;
if (Convert.ToBoolean(checkboxcell.Value)) state = CheckBoxState.CheckedNormal;
else state = CheckBoxState.UncheckedNormal;
problem went away.
2. when checkbox checked, height returned from calccellsize datasize.height = 18.++ for checkbox.
datasize = g.MeasureString(cell.EditedFormattedValue.ToString(), cellstyle.Font,
new SizeF(basewidth, maxPages), format);
when checkbox unchecked datasize.height returns 30.++
which results in different row heights when grid previewed or printed.
Font = tahoma 9.75. differents. font size smaller seem ok.
Cant help feeling something not setup correctly in my checkbox setup.
regards Ron.
|
|
|
|

|
Great Work - Thank you for sharing
|
|
|
|

|
I see you've started versioning your tool. That's a good idea, but I don't know how to tell what version I have now.
The subfolders I have in my "DGVPrinter" folder are:
* 2008-09,
* 2009-09,
* 2010-01,
* 2010-08,
* 2011-04-25,
* 2011-05-17 beta,
* 2011-06-02 beta, and now
* 2012-03-26
FYI: If you need any of the old code from way back, I guess I've got copies!
|
|
|
|

|
Any example for how to place a picture in the printing document?
Thanks Very Much
|
|
|
|

|
aureolin, thank you for the excellent code. is a question which parameter is responsible for all the columns fit the width of the sheet in one?
picture print by default
http://img254.imageshack.us/img254/1185/dgvprint.png[^]
that is, if I stretch window to full screen, and since DataGridView align it to the window, and print what is given in the picture
http://img850.imageshack.us/img850/8571/dgvprinttest2.png[^]
How fixed?
settings:
Dim Printer = New DGVPrinter
Printer.Title = "TEST"
Printer.SubTitle = FormatDateTime(Date.Today, DateFormat.LongDate)
Printer.SubTitleFormatFlags = StringFormatFlags.LineLimit Or StringFormatFlags.NoClip
Printer.PageNumbers = True
Printer.PageNumberInHeader = False
Printer.ColumnWidth = DGVPrinter.ColumnWidthSetting.Porportional
Printer.HeaderCellAlignment = StringAlignment.Near
Printer.Footer = "TESTTESTEST"
Printer.FooterSpacing = 15
Printer.PrintDataGridView(Me.dgv_prih)
modified 12 Nov '12 - 1:06.
|
|
|
|

|
Old ver.
gives me :A generic error occurred in GDI+.
Ver 4.2
gives me :Fixed row exceeds width error or something like this.
Help Please
|
|
|
|

|
Excellent piece of work. But how do you change the title, subtitle, & footer properties (e.g., bold, size, etc.)? Tks, OH
|
|
|
|

|
Dear author, is it possible somehow to add a row number for each row to the printed page? I know, that i can add a column with this information, but i think, that more people would appretiate, if this functionallity would be built-in. Example I have grid with this data Jane Doe Joe Doe I would like to have on the printed page 1 Jane Doe 2 Joe Doe If it is possible to do it know somehow, please let me know. Thank you and great job!
|
|
|
|

|
I believe it's "Proportional" not "Porportional". Otherwise, your code was really easy to just plug-in and go. Ryan C. Price
|
|
|
|

|
Hi
I'm using your lovely dll in a project I'm working on to print a datagridview using the simply version. My c++/cli coding uses:
DGVPrinter printer;
printer.Title = "A Title";
printer.PorportionalColumns = true;
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.Footer = "footer";
printer.FooterSpacing = 15;
printer.PrintDataGridView(dgvsheet);
and it works fine EXCEPT that I need the rows to be at a greater height. I was hoping the line I needed went:
printer.RowHeight =
but I've absolutely no idea what would come next.
Can I do this and, if so, how?
Brian
|
|
|
|

|
Hi again Steve,
Another minor problem - updated to your latest version and my code line of:
printer.PrintSettings.DefaultPageSettings.Landscape = true;
isn't working anymore. Has this been changed?
Joe
|
|
|
|
 |
|
|
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 | 809,492 |
| Downloads | 23,209 |
| Bookmarked | 361 times |
|
|