且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C# - 在 DaraGridView 中修改 column1 中的值并将它们放在新列中

更新时间:2023-01-12 22:03:38

您必须将每个列定义添加到您的 eOutputDGV 中,然后将三个参数传递给每个 eOutputDGV.Row代码>:

You have to add each column definition to your eOutputDGV and then to pass three parameters to each eOutputDGV.Row:

private void Button1_Click(object sender, EventArgs e)
{
    List<string> eSplit = new List<string>(eInputBox.Text.Split(new string[] { "," }, StringSplitOptions.None));

    DataGridViewTextBoxColumn eOutputGrid = new DataGridViewTextBoxColumn();
    eOutputGrid.HeaderText = "Section";
    eOutputGrid.Name = "Section";
    eOutputDGV.Columns.Add(eOutputGrid);

    eOutputGrid = new DataGridViewTextBoxColumn();
    eOutputGrid.HeaderText = "Letters";
    eOutputGrid.Name = "Letters";
    eOutputDGV.Columns.Add(eOutputGrid);

    eOutputGrid = new DataGridViewTextBoxColumn();
    eOutputGrid.HeaderText = "Numbers";
    eOutputGrid.Name = "Numbers";
    eOutputDGV.Columns.Add(eOutputGrid);

    foreach (string item in eSplit)
    {
        eOutputDGV.Rows.Add(item.Trim(), item.Trim().Substring(0, 3), item.Trim().Substring(3));
    }
}