问题描述:
DevExpress XtraGrid 网格中显示了数据,在某一时刻,我需要清除网格,怎么样可以做到呢?
问题解答:
你应该设置GridControl.DataSource属性为null,并调用Columns.Clear()方法阻止网格主视图。
[C#]
gridControl1.DataSource = null;
gridView1.Columns.Clear();
gridControl1.DataSource = null;
gridView1.Columns.Clear();
如果需要恢复原来的网格视图,你可以动态地创建一个临时的空GridView,并将它分配给GridControl。
[C#]
using DevExpress.XtraGrid.Views.Grid;
object ds;
// clear
ds = gridControl1.DataSource;
gridControl1.DataSource = null;
GridView view = new GridView(gridControl1);
view.OptionsView.ShowGroupPanel = false;
view.OptionsView.ShowColumnHeaders = false;
gridControl1.MainView = view;
// restore
gridControl1.MainView = gridView1;
gridControl1.DataSource = ds;
using DevExpress.XtraGrid.Views.Grid;
object ds;
// clear
ds = gridControl1.DataSource;
gridControl1.DataSource = null;
GridView view = new GridView(gridControl1);
view.OptionsView.ShowGroupPanel = false;
view.OptionsView.ShowColumnHeaders = false;
gridControl1.MainView = view;
// restore
gridControl1.MainView = gridView1;
gridControl1.DataSource = ds;
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/243.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/243.html