Column repeat direction in microsoft report viewer
Asked Answered
S

3

15

I am using windows form to generate Identity Card using c# and Microsoft report viewer. Everything is working fine except I could not find column repeat direction in Microsoft report viewer.

Current Scenario

My report paper size is A4. Each page can display maximum 10 individual cards. There are 2 columns in page. Each column display 5 cards. It is generating card as shown in image. The column repeat direction is vertically. It first list 1st column (1-5) and then list 2nd column (6-10).

enter image description here

My Requirement

I want the report column repeat direction to be horizontally like in the image below. First display 1 then 2 and 3 and 4 and so on.

enter image description here

Why I want to display horizontally rather than vertically?

It will save the paper. For example, if the user generate 4 Identity cards only then as per current scenario, it will generate 4 cards in column 1 and the whole page space is wasted because I can not re-use the left space.

By repeating the column direction to horizontally, the 4 cards will be displayed as in column 1, card 1 and 3 and in column 2, card 2 and 4 will be displayed. I can then cut the paper and reuse it later.

I have searched alot but could not find any solution. Any suggestion, comments or links will be helpful. I can not use any other reports. Thanks in advance.

Sublapsarianism answered 19/1, 2016 at 11:47 Comment(1)
I assume your cards are rows in a report? If so, could you post the code that generates each identity card?Crashaw
P
8

Create a matrix

Define your row grouping as

=Ceiling(Fields!CardNo.Value/2)

Define your column grouping as

=Fields!CardNo.Value Mod 2

Your report design will look something like this. Outer group is just shown for illustration purposes but you can delete it.

enter image description here

Now when you run the report. You will get the result you are looking for

enter image description here

Without any grouping header and footer. Your report output will be

enter image description here

Petropavlovsk answered 21/1, 2016 at 15:26 Comment(0)
M
1

This problem can be seen as mapping problem where you need to reshuffle your items as follow:

n -> f(n)
----------
1 -> 1
2 -> 6
3 -> 2
4 -> 7
5 -> 3
6 -> 8
7 -> 4
8 -> 9
9 -> 5
10 -> 10

n is the original position
f(n) is the mapped position

It can be seen that it follows a pattern like this:

  1. f(n) = floor(n / 2) + 1 if n is odd
  2. f(n) = (10 + n) / 2 if n is even

Thus, you may want to reshuffle the order you put your items in that following manner. That is given index of the item from 0-9 (start from 0 is following C# typical number indexer), you could do something like this:

index++;
int newIndex = index % 2 == 0 ? (10 + index) / 2 : index / 2 + 1;
newIndex--;

And you should be able to place your Cards correctly.

Note: without actually code given, this is to show how you can solve the problem conceptually.

Mallarme answered 21/1, 2016 at 12:28 Comment(0)
E
1

Another answer. This will work with or without groups on your tables.

Place two tables side by side on your report. Set the first table to a query that partitions starting at the first record and skipping by 1. Next, set the second table to a query that partitions starting at the second record skipping by 1.

Enlistee answered 21/1, 2016 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.