DevExpress控件GridControl中的布局详解 【转】
2012-10-24 13:27:28| 分类: devexpress | 标签:devexpress |举报|字号 订阅
http://www.cnblogs.com/martintuan/archive/2011/03/05/1971472.html
进行DevExpress控件GridControl的使用时,因控件的灵活性,所以用户会经常进行拖动控件的列,以达到自己满意的样式,
但下次再打开时系统就会重新还原到原有的布局风格,为了能够保持用户之前设置的风格,下次再打开时依然保持原有的风格。
在gridView中有两个方法:SaveLayoutToXml(保存布局),RestoreLayoutFromXml(恢复布局)
以下是具体的代码:
private string systempath = "C:\\Program Files\\"; ///<summary> /// 保存风格 ///</summary> ///<param name="moduleid"></param> ///<param name="saveType"></param> private void SaveLayout(string moduleid, string saveType) { string path = systempath + "窗体风格\\" + moduleid+"\\"; string file = saveType + "view.xml"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } m_gridView.SaveLayoutToXml(path+file); } ///<summary> /// 加载风格 ///</summary> ///<param name="moduleid"></param> ///<param name="saveType"></param> private void LoadLayout(string moduleid, string saveType) { string path = systempath + "窗体风格\\" + moduleid + "\\"; string file = saveType + "view.xml"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!File.Exists(path + file)) return; m_gridView.RestoreLayoutFromXml(path + file); } ///<summary> /// 布局变化时产生事件 ///</summary> ///<param name="sender"></param> ///<param name="e"></param> private void m_gridView_Layout(object sender, EventArgs e) { SaveLayout(m_controlManager.Owner.ModuleId, "Master"); } ///<summary> /// gridcontrol load Event ///</summary> ///<param name="sender">The source of the event.</param> ///<param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void m_gridControl_Load(object sender, EventArgs e) { SaveLayout(m_controlManager.Owner.ModuleId, "Default"); LoadLayout(m_controlManager.Owner.ModuleId, "Master"); }