先说保存:
UserControl control;
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { List<GridControl> listgridcontrol = new List<GridControl>(); //反射 用不到 // System.Reflection.FieldInfo[] fieldInfo = this.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); //panelControl2 if(control!=null) { foreach (Control control in this.control.Controls) { if (control is GridControl) { // listgridcontrol.Add((GridControl)control); ExportToXlsx((GridControl)control); //保存为excel } } } }
void ExportToXlsx(GridControl gridControl1)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "导出Excel";
saveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
DialogResult dialogResult = saveFileDialog.ShowDialog(this);
if (dialogResult == DialogResult.OK)
{
DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
// gridControl1.ExportToXls(saveFileDialog.FileName, options);
gridControl1.ExportToXlsx(saveFileDialog.FileName/*, options*/);
// gridControl1.ExportToExcelOld(saveFileDialog.FileName);
DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
前提先获得usercontrol 控件的对象
左侧点击时 ,pancontrol 加载你定义的usercontrol ,里边有个gridcontrol
2: 点击左侧自动找得到加载的控件的方式. 找到栏目 按F4 ,出来属性 .在tag里边添加要加的控件的路径,也就是 那个控件在哪
1:)
2: 当控件打开时. 在form里边加下边的代码.就能方便的找到 并初始化usercontrol.
public Form1() { InitializeComponent(); accordionControl1.ElementClick += (s, e) => { //创建page CreatePage(e.Element.Text, e.Element.Tag); }; } UserControl control; private void CreatePage(string caption, object tag) { if (string.IsNullOrWhiteSpace(caption) || tag == null || string.IsNullOrWhiteSpace(tag.ToString())) return; try { control = Activator.CreateInstance(Type.GetType(tag.ToString().Trim(), false, false)) as UserControl; if (control != null) { panelControl2.Controls.Clear(); panelControl2.Controls.Add(control); } } catch { throw; } }
好了.就这些......