先说保存:
 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 控件的对象  ,此控件窗口最终要加入到panelcontrol中的

左侧点击时 ,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; }
        }

好了.就这些......

补充:

问:我想问下 这个控件要怎么绑定数据

 

 

左侧栏加控件accordionControl1  找到那个栏目,
找到栏目 按F4 ,出来属性 .在tag里边添加要加的自定义控件的路径

 

 

 


页面加载时注册左侧栏点击事件,点击时,把左侧栏栏目里边的tag 取出来,这个tag里边存着你要找的栏目的对象地址,然后这个对象给实例化. panelcontrol 加载,便可以显示出来了

posted on 2018-09-20 18:25  小石头的一天  阅读(1987)  评论(0编辑  收藏  举报