我已经寻找了几个小时来将我的 char 数组直接加载到动态表中,然后再加载到数据网格视图中的方法。
尝试了几种方法,但总是有一些事情没有按计划工作。
需要:数组被逐行写入表格,从一个单元格跳到另一个单元格。
private void btn_okay(object sender, EventArgs e)
{
//reading the strings from the two text boxes
Char[] ArrayUp = rtb_up.Text.ToCharArray();
Char[] ArrayDown = rtb_down.Text.ToCharArray();
Char[] ArrayEnd = new Char [ArrayUp.Length * ArrayDown.Length];
//comparison of the two char arrays and filling the new char array
Int32 I = 0;
for (Int32 C = 0; C < ArrayDown.Length; C++)
{
for (Int32 D = 0; D < ArrayUp.Length; D++)
{
if (ArrayDown[C] == ArrayUp[D])
{
ArrayEnd[I] = '+' ;
I ++;
}
else
{
ArrayEnd[I] = '-' ;
I ++;
}
}
}
//creation of data table
DataTable Table = new DataTable();
for (Int32 E = 0; E < ArrayUp.Length; E++)
Table.Columns.Add("", typeof(Char));
for (Int32 R = 0; R < ArrayDown.Length; R++)
Table.LoadDataRow(ArrayEnd[R], LoadOption.OverwriteChanges());
//OverwriteChanges won't work
dgv_main.AutoGenerateColumns = true;
dgv_main.DataSource = Table;
}