C#获取已删除项目和已更改项目以列表

时间:2018-09-21 10:00:14

标签: c# datagridview

我有一个问题,要将所有已删除的项目以及更改后的项目都保存到新列表中。我正在使用带有可排序绑定源的datagridview。对于所有新项目,它已经在工作(代码的最后一部分)

谢谢!

namespace Levelapp
{
    public partial class LevelView : Form
    {
        FilterLevel m_filterLevel;
        int m_filterLevelTotal;

        public LevelView()
        {
            InitializeComponent();
        }

        public LevelView(FilterLevel opt)
        {
            InitializeComponent();

            m_filterLevel = opt;

            bindingSource1.DataSource = typeof(LevelResource);
            dataGridView1.DataSource = bindingSource1;            
            bindingSource1.DataSource = m_filterLevel.FoundLevels;

            m_filterLevelTotal = bindingSource1.Count;

        }

        private void newSheet_Click(object sender, EventArgs e)
        {
            string newItemName = "Sheet" + " " + "1";
            string newItemNumber = "A-00";

            LevelResource newItem = new LevelResource();
            newItem.Name = newItemName;
            newItem.Number = newItemNumber;

            bindingSource1.Add(newItem);
        }

        private void deleteSheet_Click(object sender, EventArgs e)
        {
            bindingSource1.RemoveCurrent();
        }

        private void ok_Click(object sender, EventArgs e)
        {
            for (int i = m_filterLevelTotal; i < bindingSource1.Count; i++)
            {
                bindingSource1.Position = i;
                LevelResource newSheet = bindingSource1.Current as LevelResource;             
            }
        }
    }
}

感谢您的快速回复。但是我在布尔结果行中遇到了错误。此代码将在Revit中使用。在该部分的下面,我如何将您的代码放在deleteSheet按钮下

private void deleteSheet_Click(object sender, EventArgs e)
{

    for (int i = 0; i < bindingSource1.Count; i++)
    {
        bindingSource1.Position = i;
        var view = bindingSource1.Current as DataRowView;
        bool result = view.Row.RowState == DataRowState.Added || view.Row.RowState == DataRowState.Unchanged;
        if (result)
        {
            // new or didn't modified, work as normal

        }
        else
        {
            // add to another list
        }
    }            
}

Revit Error

0 个答案:

没有答案