Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重新排列标签的对象列表,然后依次向下报告_C#_Wpf_Telerik Reporting - Fatal编程技术网

C# 重新排列标签的对象列表,然后依次向下报告

C# 重新排列标签的对象列表,然后依次向下报告,c#,wpf,telerik-reporting,C#,Wpf,Telerik Reporting,我正在尝试用Telerik Reporting制作一份标签报告(3水平x 5垂直)。我有一个对象列表(带有代码和名称的客户)。例如,该列表包含以下项目: { '001', '002', '003', '004', '005', '006', '007', '008', '009', '010', '011', '012', '013', '014', '015' }. 我尝试以下示例: 但对我来说不起作用,因为我没有任何索引字段 我在运行时将列表绑定到报表,并在预览中获得: 001 0

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

{ '001', '002', '003', '004', '005', '006', '007', '008', '009', '010', '011', '012', '013', '014', '015' }.
我尝试以下示例: 但对我来说不起作用,因为我没有任何索引字段

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

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);
            }
        }
    }
}
使用系统;
使用System.Linq;
使用System.Collections.Generic;
公共课程
{
公共静态void Main()
{
int行=5;
int列=3;
列表x=新列表{“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“10”、“11”、“12”、“13”、“14”、“15”、“16”、“17”、“18”、“19”、“20”};
对于(int i=0;iindex%columns==i).Take(rows.ToList();
foreach(h中的var s)
{
控制台。写入线(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);
        }

    }
}
使用系统;
使用System.Linq;
使用System.Collections.Generic;
公共课程
{
公共静态void Main()
{
列表x=新列表{“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“10”、“11”、“12”、“13”、“14”、“15”、“16”、“17”、“18”、“19”、“20”};
/*
*从标签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                          =>  ---     ---
*/
//字符串或对象的最终列表
最终列表=新列表();
int firstPosition=5;
//在窗口添加空项
对于(int i=0;i<(firstPosition-1);i++)
{
x、 插入(0,“-”;
}
int行=5;
int列=3;
int标签=行*列;
int pages=x.Count()/labels+((x.Count()%labels)==0?0:1);
WriteLine(“总标签{0}”,x.Count());
WriteLine(“每页{0}的标签总数”,标签);
WriteLine(“总页数{0}”,页数);
Console.WriteLine();
对于(int page=0;pageindex%columns==i).Take(rows.ToList();
foreach(h中的var s)
{
最后。添加(s);
r--;
}
对于(int j=0;j
我只需要在一个位置开始的选项

编辑: 在列表的起始位置添加(firstPosition-1)元素可解决起始位置问题:

for (int i = 0; i < (firstPosition - 1); i++)
{
    x.Insert(0, "-");
}
for(int i=0;i<(firstPosition-1);i++)
{
x、 插入(0,“-”;
}
Net Fiddle中的示例: