对标签的对象列表重新排序,然后向下报告



我正在尝试使用 Telerik 报告制作标签报告(3 水平 x 5 垂直(。我有一个对象列表(带有代码和名称的客户(。例如,列表包含以下项:

{ '001', '002', '003', '004', '005', '006', '007', '008', '009', '010', '011', '012', '013', '014', '015' }.

我尝试此示例:https://www.telerik.com/support/kb/reporting/details/how-to-create-multi-column-report---across-the-page-and-then-down但对我不起作用,因为我没有任何索引字段。

我在运行时将列表绑定到报表,在预览中,我得到:

001     006     011
002     007     012
003     008     013
004     009     014
005     010     015
But I want to get:
001     002     003
004     005     006
007     008     009
010     011     012
013     014     015

我想知道linq是否有任何方法可以按要获取的行数对列表分组进行重新排序001, 004, 007, 010, 013, 002, 005, 008, ...另一个问题是,如果项目数少于 15,我应该用空项目填充列表。谢谢。

编辑:我正在尝试这样的事情:

using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
    public static void Main()
    {
        int rows = 5;
        int columns = 3;
        List<string> x = new List<string> { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" };
        for (int i = 0; i < rows; i++)
        {
            var h = x.Where((c, index) => index % columns == i).Take(rows).ToList();
            foreach (var s in h)
            {
                Console.WriteLine(s);
            }
        }
    }
}

我找到了解决方案。

using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
    public static void Main()
    {
        List<string> x = new List<string> { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" };
        /*
         *                                                                  Begin in the label #5  
         * 001      006     011         =>  001     002     003         =>  ---     ---     ---    
         * 002      007     012         =>  004     005     006         =>  ---     001     002    
         * 003      008     013         =>  007     008     009         =>  003     004     005    
         * 004      009     014         =>  010     011     012         =>  006     007     008    
         * 005      010     015         =>  013     014     015         =>  009     010     011 ...
         * ----------------------------------------------------------------------------------------
         * 016                          =>  016     017     018
         * 017                          =>  019     020
         * 018                          =>  ---     ---
         * 019                          =>  ---     ---
         * 020                          =>  ---     ---
        */
        // Final list of strings or objects
        List<string> final = new List<string>();
        int firstPosition = 5;
        // Add empty items at the beggining
        for (int i = 0; i < (firstPosition - 1); i++)
        {
            x.Insert(0, "-");
        }
        int rows = 5;
        int columns = 3;
        int labels = rows * columns;
        int pages = x.Count() / labels + ((x.Count() % labels) == 0 ? 0 : 1);
        Console.WriteLine("Total labels {0}", x.Count());
        Console.WriteLine("Total labels per page {0}", labels);
        Console.WriteLine("Total pages {0}", pages);
        Console.WriteLine();
        for (int page = 0; page < pages; page++)
        {       
            for (int i = 0; i < columns; i++)
            {
                int r = rows;
                var h = x.Skip(page * labels).Where((c, index) => index % columns == i).Take(rows).ToList();
                foreach (var s in h)
                {
                    final.Add(s);
                    r--;
                }
                for (int j = 0; j < r; j++)
                {
                    final.Add("-");
                }
            }           
        }
        foreach (var s in final)
        {
            Console.WriteLine(s);
        }
    }
}

我只需要从一个位置开始的选项。

编辑:在列表开头添加(firstPosition - 1(元素可解决起始位置:

for (int i = 0; i < (firstPosition - 1); i++)
{
    x.Insert(0, "-");
}

.Net 小提琴中的示例:https://dotnetfiddle.net/Gh1t3S

最新更新