【发布时间】:2013-11-20 15:36:41
【问题描述】:
我需要帮助了解 doc.save 的工作原理。
背景:得到了一个从 xml 文档中获取属性的 c# 方法。然后我将这些作为 Windows 形式的 DataGridView 的数据集发送。我试图做到这一点,以便在用户编辑表单时更新 xml 值。
首先我解析 XML:Updater.cs
XmlNodeList elemList = doc.GetElementsByTagName("property");
for (int i = 0; i < elemList.Count; i++)
{
if (elemList[i].Attributes["value"] != null)
{
AppProperty property = new AppProperty(elemList[i].Attributes["name"].Value, elemList[i].Attributes["value"].Value);
properties.Add(property);
}
}
然后我将它发送到表单并更新表单数据集: Form1.cs
private void Form1_Load(object sender, System.EventArgs e)
{
this.dataGridView1.SelectionMode =
DataGridViewSelectionMode.FullRowSelect;
this.dataGridView1.DataSource = properties;
this.dataGridView1.AutoGenerateColumns = false;
}
现在当用户编辑我触发事件监听器:Form.cs
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
updater.updateSave();
}
然后返回到我的更新程序类并保存文档:Updater.cs
public void updateSave()
{
foreach (string f in filePaths)
doc.Save(f);
}
该文件看起来像是已保存,因为它已将“修改日期:”更新到我使用保存的那一刻。我确定有一些参考值混淆,但我无法弄清楚
为什么没有做出改变?
【问题讨论】:
标签: c# xml datagridview xmldocument