I'm trying to use Documents Reports and seem to be having some basic problems (or just things that I don't understand yet.
For example. I'm trying to set the height of the report header. I've got a header with an image and then n-lines of text. The text can be variable in length and number of lines. What I'd like to be able to do is to use the various "Addxxx" methods and either have the height calculated based on the content or give me some method of getting the resulting height. This does not seem to be available or I'm missing something basic.
I've also got a grid with multiple columns. I want to set the width of the first column based on the widest text in the column cells. Again, I'd like to have the grid figure that out for me similar to what I can have the UltraGrid do for me with autoresize. Instead, I tried the following
Infragistics.Documents.Report.Text.Style boldStyle = new Infragistics.Documents.Report.Text.Style( new Infragistics.Documents.Graphics.Font("Verdana", 8, Infragistics.Documents.Graphics.FontStyle.Normal), Infragistics.Documents.Graphics.Brushes.Black);
//* Since I don't seem to be able to get to the base font from the style I did
Font textFont = new Font(normalStyle.Font.Name, normalStyle.Font.Size, FontStyle.Regular);
//Then, loop over the text and try to get the width
Int32 maxColumnWidth = 0;
Size cellSize;Size proposedSize = new Size(int.MaxValue, int.MaxValue);TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; //TextFormatFlags.GlyphOverhangPadding | TextFormatFlags.Left | TextFormatFlags.ExternalLeading | TextFormatFlags.WordBreak; foreach ( String thing in _myListOfThings )
{
String newThing = thing.Replace("<br/>", System.Environment.NewLine); cellSize = TextRenderer.MeasureText(newThing, textFont, proposedSize, flags); maxColumnWidth = Math.Max(tastableColumnWidth, cellSize.Width);
}
textFont.Dispose();
gridColumn = grid.AddColumn();gridColumn.Width = new Infragistics.Documents.Report.FixedWidth((float) maxColumnWidth);
This does calculate something that looks reasonable but when I get the exported PDF result the first column is about 40% wider than what I think I calculated in the above.
In any case, is there something I'm missing here that would make Reports more usable?
Thanks
Hi Neil,
I'm not really clear on what you are doing here. If you are exporting a grid to a PDF, then the AutoSize property on the UltraGridDocumentExporter will take care of autosizing the column for you.
If you are trying to do this manually for some reason, then you could AutoSize the grid column to the contents by simply calling the PerformAutoResize method on the column. You don't have to loop.
The only tricky thing is that the grid column will size based on the scale mode of the screen (pixels) and the PDF document works with points. So you would have to convert pixels to points. There's a static utility method to do this:
Infragistics.Win.UltraWinGrid.DocumentExport.Utilities.PixelsToPoints
I'm not exporting a grid I'm buiding a grid from other data. My "like..." comment was just an example of the autosize I was looking for.
In the response from Matt above he suggests using AutoHeight on the header but I'm not sure exactly how to use an autoheight instance here.
I tried
Infragistics.Documents.Report.Section.ISectionHeader sectionHeader = section.AddHeader();
sectionHeader.Height = Infragistics.Documents.Report.AutoHeight.Instance
but (of course) this returns an autoheight class and can't be assigned to the height property of the header so I'm not sure how to use this to make sure that the header is sized automatically.
Neil