【原创】DevExpress控件GridControl中的布局详解

在进行DevExpress控件GridControl的使用时,因控件的灵活性,所以用户会经常进行拖动控件的列,以达到自己满意的样式,

但下次再打开时系统就会重新还原到原有的布局风格,为了能够保持用户之前设置的风格,下次再打开时依然保持原有的风格。

在gridView中有两个方法:SaveLayoutToXml(保存布局),RestoreLayoutFromXml(恢复布局)

 以下是具体的代码:

 
    
private string systempath = " C:\\Program Files\\ " ;
///
/// 保存风格
///

///
///
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);
}
///
/// 加载风格
///

///
///
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);
}
///
/// 布局变化时产生事件
///

///
///
private void m_gridView_Layout( object sender, EventArgs e)
{
SaveLayout(m_controlManager.Owner.ModuleId,
" Master " );
}

///
/// gridcontrol load Event
///

/// The source of the event.
/// The instance containing the event data.
private void m_gridControl_Load( object sender, EventArgs e)
{
SaveLayout(m_controlManager.Owner.ModuleId,
" Default " );

LoadLayout(m_controlManager.Owner.ModuleId,
" Master " );
}

转载于:https://www.cnblogs.com/martintuan/archive/2011/03/05/1971472.html

你可能感兴趣的:(【原创】DevExpress控件GridControl中的布局详解)