我是C#的新手。 我希望我的数据首先填充第一列,然后在用用户定义行填充第一列后,数据将填充到下一列。当数据达到行限制时,数据将填充下一列。行和列是动态的取决于用户输入。谢谢 链接中的屏幕截图
输入:
预期产出:
string[] separators = { ",", " " };
int[] row = new int[Convert.ToInt32(textBox1.Text)];
string value = textBox2.Text ;
string[] words = value.Split(separators, StringSplitOptions.RemoveEmptyEntries);
ArrayList val = new ArrayList();
val.Add(value);
foreach (var word in words)
{
listView1.Items.Add(word);
listView1.View = View.List;
}
答案 0 :(得分:1)
以下是根据用户输入行计数来填充行的示例。
string[] separators = { ",", " " };
int rowCount = Convert.ToInt32("2");
string value = "2 5 6 7 8 9 0 2 1 3 4 5 6";
string[] words = value.Split(separators, StringSplitOptions.RemoveEmptyEntries);
string[] rows = new string[rowCount];
for (int i = 0; i < words.Length; i++)
{
int mod = i % rowCount;
rows[mod] += words[i] + " ";
}
foreach (string item in rows)
{
listView1.Items.Add(item);
}
listView1.View = View.List;