首页 > 解决方案 > 如何重置 pivotGridControl 设置(DevExpress)?

问题描述

Сannot update 表格butReset_Click不能RestoreLayoutFromRegistry从另一个表格工作。怎么做才对?我从另一个表单创建了一个表单,有必要pivotGridControl从 2 个表单重置设置。我无法重置设置。

namespace WindowsFormsApp4
    {
    
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                butReset.Click += new System.EventHandler(butReset_Click);
                pivotGridControl1.SaveLayoutToRegistry(regKey);
            }
    
           string regKey = "DevExpress\\XtraPivotGrid\\Layouts\\PivotGridLayout";
            
            public Button butLoad = new Button();
            public Button butReset = new Button();
    
            public void LoadBtn_Click(object sender, EventArgs e)
            {
                Form1 fr = new Form1();
                Form form = new Form();
                form.Show();
                ListBox listBox1 = new ListBox();
                listBox1.Size = new System.Drawing.Size(200, 100);
                listBox1.Location = new System.Drawing.Point(10, 10);
                form.Controls.Add(listBox1);
                listBox1.MultiColumn = true;
                listBox1.SelectionMode = SelectionMode.MultiExtended;
    
                DirectoryInfo dir = new DirectoryInfo(@"E:\");
                FileInfo[] files = dir.GetFiles("*.txt");
    
                butReset.Text = "Сбросить настройки";
                butReset.Location = new Point(140, 160);
                form.Controls.Add(butReset);
    
                butLoad.Text = "Принять";
                butLoad.Location = new Point(30, 160);
                form.Controls.Add(butLoad);
    
                var fileNamesWithoutExtension = files
                    .Select(fi => Path.GetFileNameWithoutExtension(fi.Name));
                foreach (string fn in fileNamesWithoutExtension)
                {
                    listBox1.Items.Add(fn.ToString());
                }
    
    
            }
    
            private void SaveBtn_Click(object sender, EventArgs e)
            {
                pivotGridControl1.RestoreLayoutFromRegistry(regKey);
    
            }
    
            static public void butReset_Click(object sender, EventArgs e)
            {
               Form1 er = new Form1();
             
                er.pivotGridControl1.RestoreLayoutFromRegistry(er.regKey);
                //MessageBox.Show("dsdsdfsdf");
    
            }
    
        }
    }

标签: c#winformsdevexpress

解决方案


使用PivotGridOptionsDataField.Reset()方法将所有选项重置为其默认值。在你的情况下

static public void butReset_Click(object sender, EventArgs e)
{
    pivotGridControl1.Reset();
}

参考文档:https ://docs.devexpress.com/CoreLibraries/DevExpress.XtraPivotGrid.PivotGridOptionsDataField.Reset


推荐阅读