首页 > 解决方案 > 从 DataGridViewRowCollection c# 添加行

问题描述

所以,我有一个问题。
我想DataGridViewRow通过使用来动态更改通过包装它的所有内容List<DataGridViewRowCollection>。这是一些片段

public List<DataGridViewRowCollection> colTrx = new List<DataGridViewRowCollection>();
     // By using colTrx As List, I can add some row collections by added into it

public int pointerGrid = 0;

public void createDatas()
{
    if(gridTab.Rows.Count != 0)
    {
       colTrx.add(someGrid.Rows);
       point += 1;
    }
}

public void getData()
{
     if(someGrid.Rows.Count != 0)
     {
        someGrid.Rows.Clear();
     }
     else
     {
        DataGridViewRowCollection ollColl = colTrx[pointerGrid - 1];

        foreach (DataGridViewRow kkk in ollColl.Cast<DataGridViewRow>())
        {
            someGrid.Add(kkk);
        }

        //Something wrong here, it won't add row from DataGridViewRowCollection

        pointerGrid -= 1;
    }
}

目标是:

1. 通过将一些行添加someGridcolTrx
2. 清除行someGrid
3. 当用户触发按钮时,从 4. 获取数据colTrx[pointerGrid - 1]
设置行




我怎样才能做到这一点?

标签: c#winformsdatagridview

解决方案


推荐阅读