Hi,
Can you please let me know if this is possible in grid printing.
I have a grid with 8 columns. There is just one row in the grid .Due to the text size and width of the columns the grid prints 5 columns in page 1 and 3 columns in page 2.
I would like to print 5 columns, followed by the other 3 columns on the same page . This would help in not seeing much of white spaces between the 2 pages, as there is just one row of data and the grid can as well use the space left behind in page 1.
Output currently is
Page 1
column 0 column1 column2 column3 column4
-------------data------data------data------
Page 2
column5 column6 column7
---data------data------data------
Expected output
--data------data------data------
Thank you.
The grid can't automatically wrap a row onto a page.
But if you know how many columns fit on a page, you could adjust the layout of your grid so that the columns in the row are one atop the other using either Groups and Levels or RowLayouts.
You can do this on the print layout which is passed into the InitializePrint or InitializePrintPreview events so that it does not affect the layout of the on-screen grid.
Setting up a RowLayout at run-time can be pretty tricky if you are not already familiar with GridBagLayouts. So here's some sample code.
private void ultraGrid1_InitializePrintPreview(object sender, Infragistics.Win.UltraWinGrid.CancelablePrintPreviewEventArgs e) { UltraGridBand band = e.PrintLayout.Bands[0]; band.RowLayoutStyle = RowLayoutStyle.ColumnLayout; // Columns 0 through 4 are fine where they are, so we don't need to do anything to them. // Adjust columns 5-7 so they are under 0-2. for (int i = 5; i < 8; i++) { UltraGridColumn columnInTopRow = band.Columns["Column " + (i - 5).ToString()]; UltraGridColumn columnUnderneath = band.Columns["Column " + i.ToString()]; columnUnderneath.RowLayoutColumnInfo.OriginX = columnInTopRow.RowLayoutColumnInfo.OriginXResolved; columnUnderneath.RowLayoutColumnInfo.SpanX = columnInTopRow.RowLayoutColumnInfo.SpanXResolved; columnUnderneath.RowLayoutColumnInfo.OriginY = columnInTopRow.RowLayoutColumnInfo.OriginYResolved + columnInTopRow.RowLayoutColumnInfo.SpanYResolved; } }
Hi ,
Please see the attachment for current ouput (grid1) and expected output (grid2)
Mike thanks for your sample . However when I print, I see that all the column header are placed atop each other followed by cell data. However I want column header to be placed atop of cell data then again column header atop of next cell data.
Please see the attachment. The current display of data is of grid 1 in attachment. However I would like to format the data so that the information is displayed as in grid 2 of the same attachment.
Can you please let me know the components that affect this , also any sample data will be of use.
Based on our phone conversation I will look into this question.
It looks like there needs to be a modification to the code based on your layout design
Your image indicates that the columns are actually positioned
(3 columns over 3 columns over 2 columns)
And I think Mike assumed that you expected there to be 5 columns over 3 columns
Marianne
Thanks Marianne. But however I had internally tweaked the code given by Mike becuase I wanted to show only 3 columns per line. Thus you would see that output in the image 1 . My main concern is to see the output as seen in image 2 ( Having the arrangment of columns should not really matter ).
Marianne,
Thanks for your reply.However the question is little different. Firstly to avoid any confusion , i have created a sample project (attached to this post).
Run the sample project , click on the button (Normal Print Preview). The print preview document prints 6 columns on page 1 and again prints 2 columns on page 2.
Thus there is lot of empty space left behind in page 1. Thus I want the page 2 data also to reappear in page 1 itself. Now if you click on button ( Print Preview by placing all data in one page.).. Notice that the data starts appearing on the same page. But the column headers are arranged first followed by the cell data.
Instead I would like to view the data as shown in image (in the same folder) of the attachment.
If I Use the option band.RowLayoutLabelStyle = RowLayoutLabelStyle.WithCellData; (uncomment this line in the code). This will ensure that the column header is repeated for each cell data, which is not the expected output.
Hi
I’m going to jump back in here.
I believe what you want to use in addition to Mikes code is
band.RowLayoutLabelStyle = RowLayoutLabelStyle.Separate;
That will cause the labels to be at the top of the form and all the datarows to display underneath.
I ran your sample and made some modification so that you can see the impact of the RowLayoutLabelStyle. Primarily I added some buttons to trigger the normal print preview and a single page print preview using Mike’s recommendation. I also added a check box so that you can set the RowLayoutLabelStyle to Separate or WithCellData.
Let me also recommend that you take a look at one of our Samples.
Look in Grids > WinGrid > Samples Explorer
Then run the V3 RowLayout sample and see if need to incorporate some of that design into your layout.
One tab demonstrates creating the form in Design and another tab shows how to build the same form in code. If you open the source code and look for the frmRowLayout and then look for the SetupRowLayoutForEmployeesRuntimeGrid method, it will give you some ideas about how you can control the layout.
The last tab “RegularView” allows you to work with properties and see the impact on the layout in the running sample.
Let me know if I can help you further.
Mike,
Please discard the previous posts, since this is causing lot of confusion.
Please see the attached sample code.
if you click button "normal print preview", the output produced is 6 columns in page 1 and 2 columns in page 2 (Column 6 was repeated ,becuase it was chopped in page 1). since the grid contains only 2 rows , there is lot of empty space in page 1 and page2 . What I would like to do instead is to print page 2 data on the same page i.e on page 1 itself . This will help in not seeing much of empty space. Expected output is attached as an image .
Please let me know how this can be achieved. I have a project deadline of this weekend, so your help is much appreciated.
Please note :- If the following below note is causing any confusion , please discard note below.
Please click on Click on "Print preview by placing all data in one page" in the sample project.
To come up with some way of achieving solution to the above problem, I thought that lets diplay 5 columns , followed by 3 columns underneath the top ones. I followed the sample code (displayed above by you). This gives me the output as follows
Column headers of Col 0 through Col 4 are arranged followed by Col 5 through Col 7 (headers) underneath the top column headers. After the arrangement of the column headers the cell data is placed accordingly.
But this does not look like the expected output. The reason is that , I want to show only the data of Col 0 through Col 4 followed by their cell data, Then it should display the column headers Col 5 through 7 followed by their respective cell data. But the output that i am getting is not doing this.
In simple terms , it should append the page 2 data to page 1.
Please let me know what tweak is needed to get the required output in the sample code.
Thanks again. Looking forward to your reply.
I'm getting a bit lost here. Your most recent sample doesn't seem to match up to what you were showing in the previous screen shot. The original screen shots you posted show exactly what you would get if you used band.RowLayoutLabelStyle = RowLayoutLabelStyle.WithCellData.
But now the new screen shot has column headers with two cells under each one and this is pretty arbitrary, so I have no idea what you want the output to look like or how you determine which column goes under which header. I think you will need to experiment a bit with RowLayouts and see if you can achieve the look you want. Is it possible to hide the column header for a column using the column.RowLayoutInfo.LabelStyle and setting it to None, so it seems like what you want to do here is possible.
Regarding the pages, I don't think there's much you can do about that, except to ensure that your layout doesn't create more than one page. Unfortunately, there's really no way to do that, which is why I mentioned in my first post that this is only really possible if you already know that the grid layout fits on a single page. You can use the FitWidthToPages property on the InitializePrint/InitializePrintPreview event args to force the grid to fit on a single page. But I'm not really sure what criteria you are using to create your levels and headers so that may not be feasible for you.