Пример #1
0
 public static void LoadOrder(BGridViewContorl dgv)
 {
     try
     {
         loadDoc(dgv.AAXmlFileName);
         if (xmlDoc != null)
         {
             var items = xmlDoc.SelectNodes("/root/" + dgv.AAXmlFileName + "/Item");
             if (items.Count == dgv.Columns.Count)
             {
                 foreach (XmlNode node in items)
                 {
                     foreach (DataGridViewColumn c in dgv.Columns)
                     {
                         if (c.DataPropertyName == node.Attributes["column"].Value)
                         {
                             c.DisplayIndex = Convert.ToInt32(node.Attributes["index"].Value);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ee)
     {
     }
 }
Пример #2
0
        public static void SaveOrder(BGridViewContorl dgv)
        {
            try
            {
                if (dgv != null && dgv.Columns.Count > 1 && !string.IsNullOrWhiteSpace(dgv.AAXmlFileName))
                {
                    loadDoc(dgv.AAXmlFileName);
                    var dvroot = xmlDoc.SelectSingleNode("/root/" + dgv.AAXmlFileName);

                    if (dvroot == null)
                    {
                        var root = xmlDoc.SelectSingleNode("/root");
                        var node = xmlDoc.CreateElement(dgv.AAXmlFileName);
                        root.AppendChild(node);
                        dvroot = node;
                    }
                    dvroot.RemoveAll();
                    foreach (DataGridViewColumn c in dgv.Columns)
                    {
                        var          node   = xmlDoc.CreateElement("Item");
                        XmlAttribute column = xmlDoc.CreateAttribute("column");
                        column.Value = c.DataPropertyName;
                        XmlAttribute index = xmlDoc.CreateAttribute("index");
                        index.Value = c.DisplayIndex.ToString();
                        node.Attributes.Append(column);
                        node.Attributes.Append(index);
                        dvroot.AppendChild(node);
                    }
                    xmlDoc.Save(path);
                }
            }
            catch (Exception ee) {
            }
        }