c# - C# 获取已删除的项目和更改的项目以列出
问题描述
我有一个问题要将所有已删除的项目以及已更改的项目添加到新列表中。我正在使用带有可排序绑定源的数据网格视图。对于所有新项目,它已经在工作(代码的最后一部分)
谢谢!
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;
}
}
}
}
感谢您及时的回复。但我在 bool 结果行出现错误。此代码将在 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
}
}
}
解决方案
推荐阅读
- r - 使用 lapply() 计算比例
- ios - VisionKit 框架 iOS 13 中的 iOS 应用程序崩溃
- python - 解析字符串以查找元素
- javascript - 从函数获取坐标数组到vue突变
- sql - 从表中选择“姓名”+ (':__________')
- regex - 正则表达式替代负前瞻
- fullscreen - 如何解决视频全屏后被导航栏覆盖的问题
- azure - 将后端服务部署到 Azure Web 应用服务时出现 HTTP 错误 500.30
- javascript - React 在浏览器后退按钮上显示自定义模式
- mysql - 带有 concat 的 SQL 查询列别名不起作用