ComponentOne GridView for ASP.NET WebForms
In This Topic
    Setting Grouping Properties at Run Time
    In This Topic

    You can also set the Grouping properties at run time. This gives you extra flexibility because you can set up the grouping based on user selections.

    For example, the code below configures the grid to display the same data in one of four modes selectable by the user (the full sample is available in the distribution package):

    Heading Text

    Visual Basic
    Copy Code

    Private Sub _rblView_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ' set up grouping/merging

        Dim col As C1.Web.Wijmo.Controls.C1GridView.C1Field = C1GridView1.Columns(0)

        Select Case _rblView.SelectedItem.Text

            ' Traditional Mode: no grouping or merging

            Case "Traditional"

                col.Visible = True

                col.RowMerge = C1.Web.Wijmo.Controls.C1GridView.RowMerge.None

                col.GroupInfo.Position = C1.Web.Wijmo.Controls.C1GridView.GroupPosition.None

            ' Merged: no grouping, similar values merged down the columns

            Case "Merged"

                col.Visible = True

                col.RowMerge = C1.Web.Wijmo.Controls.C1GridView.RowMerge.None

                col.GroupInfo.Position = C1.Web.Wijmo.Controls.C1GridView.GroupPosition.None

            ' Grouped: grouped with collapsible headers, grouped values merged.

            Case "Grouped"

                col.Visible = True

                col.RowMerge = C1.Web.Wijmo.Controls.C1GridView.RowMerge.None

                col.GroupInfo.Position = C1.Web.Wijmo.Controls.C1GridView.GroupPosition.Header

            ' Summary: grouped with collapsible headers, grouped values hidden.

            Case "Summary"

                col.Visible = False

                col.RowMerge = C1.Web.Wijmo.Controls.C1GridView.RowMerge.None

                col.GroupInfo.Position = C1.Web.Wijmo.Controls.C1GridView.GroupPosition.Header

        End Select

    End Sub

    Heading Text

    C#
    Copy Code

    private void _rblView_SelectedIndexChanged(object sender, System.EventArgs e)

    {

        // set up grouping/merging

        C1.Web.Wijmo.Controls.C1GridView.C1Field col = C1GridView1.Columns[0];

        switch (_rblView.SelectedItem.Text)

        {

            // Traditional Mode: no grouping or merging

            case "Traditional":

                col.Visible = true;

                col.RowMerge = C1.Web.Wijmo.Controls.C1GridView.RowMerge.None;

                col.GroupInfo.Position = C1.Web.Wijmo.Controls.C1GridView.GroupPosition.None;

                break;

            // Merged: no grouping, similar values merged down the columns

            case "Merged":

                col.Visible = true;

                col.RowMerge = C1.Web.Wijmo.Controls.C1GridView.RowMerge.None;

                col.GroupInfo.Position = C1.Web.Wijmo.Controls.C1GridView.GroupPosition.None;

                break;

            // Grouped: grouped with collapsible headers, grouped values merged.

            case "Grouped":

                col.Visible = true;

                col.RowMerge = C1.Web.Wijmo.Controls.C1GridView.RowMerge.None;

                col.GroupInfo.Position = C1.Web.Wijmo.Controls.C1GridView.GroupPosition.Header;

                break;

            // Summary: grouped with collapsible headers, grouped values hidden.

            case "Summary":

                col.Visible = false;

                col.RowMerge = C1.Web.Wijmo.Controls.C1GridView.RowMerge.None;

                col.GroupInfo.Position = C1.Web.Wijmo.Controls.C1GridView.GroupPosition.Header;

                break;

        }

    }

    ·         C#

       

    * Sample Project Available

    For the complete sample, see the Grouping sample located on the ComponentOne HelpCentral Sample page.