string path = Application.StartupPath + @"\XML\"+this.Name+".xml";
XDocument doc = XDocument.Load(path);
var query = (from item in doc.Element("root").Elements()
select new
{
Name = item.Value,
Visible = item.Attribute("visible") == null ? (string)null : item.Attribute("visible").Value,
Order = item.Attribute("order") == null ? (string)null : item.Attribute("order").Value,
Width = item.Attribute("width") == null ? (string)null : item.Attribute("width").Value
}).ToList();
foreach (var item in query)
{
foreach(var column in this.ultraGrid1.DisplayLayout.Bands[0].Columns)
{
if(column.Key.ToString()==item.Name)
{
column.Header.VisiblePosition=int.Parse(item.Order);
column.Hidden=item.Visible.ToBoolean();
column.Width = item.Width.ToInt16();
}
}
}
获取一个然后进行修改
XElement xe = (from db in doc.Element("root").Elements("Column") where db.Attribute("order").Value.ToInt16() == e.ColumnHeaders[i].VisiblePosition.ToInt16() select db).Single();
try
{
xe.Element("company").Attribute("value").Value = Company;
xe.Element("server").Attribute("value").Value = Server;
xe.Element("database").Attribute("value").Value = DataBase;
xe.Element("username").Attribute("value").Value = UserName;
xe.Element("password").Attribute("value").Value = Password;
doc.Save(filePath);
}
catch
{
}