【问题标题】:how to clear all data and layout of a ultragrid without its summerize layout如何在没有汇总布局的情况下清除超网格的所有数据和布局
【发布时间】:2013-01-30 07:51:12
【问题描述】:

有什么方法可以设置 UltraGrid 的数据源而不删除其摘要行?

我的 Windows 窗体应用程序中有一个 ultragrid gvResult

用户可以选择列并以另一种形式对它们进行排序,然后通过按“应用”按钮将这些更改应用到 gvResult。

此外,gvResult 必须显示行计数器摘要。

我在应用用户更改之前清除了 gvResult,否则排序算法不会更改为用户设置的。

gvResult.DataSource = new DataTable();
gvResult.DataSource = dataTable_With_New_Set_And_Sort_of_Columns;

还有一个问题!它也删除了行计数器摘要以及gvResult 的其他布局设置。我在infragistics forum 上搜索,发现以下代码;但是,第一个问题仍然存在。列排序不变。

BindingSource bs = new BindingSource();
bs.DataSource = typeof(DataTable);
bs.DataSource = dataTable_With_New_Set_And_Sort_of_Columns;
gvResult.DataSource = bs;

你有什么建议吗?

对不起,我的英语不好。

编辑:我尝试了类似下面的方法,但它不再起作用:

DataTable dtTest = new DataTable();
dtTest.Rows.Clear();
dtTest = Method_That_Returns_DataTable_With_New_Set_And_Sort_of_Columns();
gvResult.DataSource = dtTest.Copy();

【问题讨论】:

  • 试过bs.Clear()?
  • 嗨 spajce,是的,我已经尝试过了,但我收到了“无法清除此列表”错误。
  • 尝试清除您的DataTablegvResult.Clear();
  • 你是说我的 ultragrid 吗?因为 gvResult 是一个 ultragrid。但是 ultragrid 没有任何 Clear() 方法。
  • 这是什么dataTable_With_New_Set_And_Sort_of_Columns?有没有像dataTable_With_New_Set_And_Sort_of_Columns.Rows.Clear()dataTable_With_New_Set_And_Sort_of_Columns.Clear()

标签: c# winforms ultrawingrid


【解决方案1】:

M_Mogharrabi,

如果我理解你的想法,这可能对你有用。

每当您将数据绑定到 UltraGrid 时,每次都会触发 IntializeLayout 事件,因此您需要确保将摘要行设置为在 InitializeLayout 函数中可见。

像这样:

    private void yourUltraGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
    {
        // Define Global settings like you usually do
        // ....

        // Configure your UltraGrid columns.
        //// ID
        //// Caption: "ID"
        e.Layout.Bands[0].Columns[ColumnKeyA].Header.Caption = "ID";
        e.Layout.Bands[0].Columns[ColumnKeyA].Header.VisiblePosition = 0;
        e.Layout.Bands[0].Columns[ColumnKeyA].Width = 50;
        // Any additional settings you may want for this column.
        // Repeat for each column...


        // Then add this block under each column you want to add Summary value to.

        // This if function is critical to avoid summary rows from duplicating itself.
        // Check to see if the Summary does not exist.
        if (!e.Layout.Bands[0].Summaries.Exists("yourSummaryKey"))
        {
            // If it doesn't exist, create the summary.
            SummarySettings summary;
            summary = e.Layout.Bands[0].Summaries.Add("yourSummaryKey", SummaryType.Sum,
                e.Layout.Bands[0].Columns[ColumnKeyA]);

            // Change the Display Formatting if you desire.
            // This display format will change it to just numbers
            // instead of "Sum = 1234"
            summary.DisplayFormat = "{0}";

            // Change the horizontal alignment for the cell text.
            summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Left;

            // Apply any other settings to this summary column
            // if needed.
            // ...
        }
    }

注意:摘要行仅适用于父乐队。无法为子乐队设置摘要行。

如果要重置数据网格,请将以下内容添加到您的代码中(但不在 InitializeLayout 函数中)

    private void btnReset_Click(object sender, EventArgs e)
    {
        yourUltraGrid.DeleteSelectedRows();

        // This will trigger the yourUltraGrid_InitializeLayout event
        // and will ensure the column settings are defined.
        yourUltraGrid.DataSource = Prototype.ugGetResourcePlanning();
    }

这将保留对排序算法所做的任何更改。所以在这个例子中:如果用户对 UltraGrid 进行了任何更改并随之更改了排序算法。点击“重置”按钮只会恢复数据,不会恢复排序算法。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2018-04-11
    • 2017-11-02
    • 1970-01-01
    • 2018-05-14
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    相关资源
    最近更新 更多