DataGridView 中的 3 个字符串数组
3 string arrays in a DataGridView
我在 C# 中有 3 个字符串数组
string[] ARRAY1 = {HELLO 1, HELLO2 ,...}
string[] ARRAY2 = {COOKIE 1, COOKIE 2,...}
string[] ARRAY3 = {C# 1, C# 2,...}
我想像这样在 DataGridView 中显示它们
Picture
我该怎么做?
我正在尝试,但它看起来不像图片(这是我第一次使用 DataGridViews)。
希望有人能帮助我!
由于您只有 3 个数组,您可以在设计器中手动 add the columns。
如果你想在代码中做到这一点:
yourDataGridView.Columns.Add("yourColumnName", "theHeaderText");
如果您想添加行(索引取决于 ARRAY1 的长度)
string[] ARRAY1 = {"HELLO 1", "HELLO 2"};
string[] ARRAY2 = {"COOKIE 1", "COOKIE 2"};
string[] ARRAY3 = {"C# 1", "C# 2"};
public void AddArraysToDataGridView ()
{
for (int i = 0; i < ARRAY1.Length; i++)
{
yourDataGridView.Rows.Add(i, ARRAY1[i], ARRAY2[i], ARRAY3[i]);
}
}
如果要添加,只需调用 AddArraysToDataGridView ()
函数即可。
这是结果(我不知道如何删除第一列。)
我在 C# 中有 3 个字符串数组
string[] ARRAY1 = {HELLO 1, HELLO2 ,...}
string[] ARRAY2 = {COOKIE 1, COOKIE 2,...}
string[] ARRAY3 = {C# 1, C# 2,...}
我想像这样在 DataGridView 中显示它们 Picture
我该怎么做? 我正在尝试,但它看起来不像图片(这是我第一次使用 DataGridViews)。 希望有人能帮助我!
由于您只有 3 个数组,您可以在设计器中手动 add the columns。 如果你想在代码中做到这一点:
yourDataGridView.Columns.Add("yourColumnName", "theHeaderText");
如果您想添加行(索引取决于 ARRAY1 的长度)
string[] ARRAY1 = {"HELLO 1", "HELLO 2"};
string[] ARRAY2 = {"COOKIE 1", "COOKIE 2"};
string[] ARRAY3 = {"C# 1", "C# 2"};
public void AddArraysToDataGridView ()
{
for (int i = 0; i < ARRAY1.Length; i++)
{
yourDataGridView.Rows.Add(i, ARRAY1[i], ARRAY2[i], ARRAY3[i]);
}
}
如果要添加,只需调用 AddArraysToDataGridView ()
函数即可。
这是结果(我不知道如何删除第一列。)