Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1775
Hidden in Multicolumn (UltraWebGrid)
posted

Hello!

I'm trying to hide columns in a multi header. But the behavior of the grid for me unpredictable. Does this principle the possibility? Below describe the way I am trying to use it.

I formed the following table:

Trying to hide the column by specifying its name.

1. Hide the column "name"

2. Showing the column "name"

3. Again, hide the column name - as a result everything is in order.

All subsequent manipulations with any columns are correct. I would like to clarify that I'm doing wrong. The source code of algorithms, which is hiding, is presented below.

*.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Web;
using System.Web.UI;
using System.Diagnostics;
using System.Data;
using Infragistics.WebUI.WebDataInput;
using System.Xml;
using Infragistics.Documents.Graphics;
using Infragistics.Web.UI.GridControls;
using Infragistics.WebUI.UltraWebGrid;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Reflection;


namespace WebApplication1
{
    public partial class MyPage : Page
    {
        /// <summary>
        /// Initial setting headlines
        /// </summary>
        public HeadersCollection OrignHedersOptions
        {
            get { return this.Session["HeadersCollection"] as HeadersCollection; }
            set { this.Session["HeadersCollection"] = value; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {           
            DataTable dt = "People";
            dt.Columns.Add("index", typeof(int));
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("sex", typeof(bool));

            for (int i = 0; i <= 10; i++)
            {
                dt.Rows.Add(new object[] { i, "Tom" + i, true });
            }           
            UltraWebGrid1.DataSource = dt;          
            if (!this.IsPostBack)
            {
                UltraWebGrid1.DataBind();
            }          
        }
       
        protected void UltraWebGrid1_InitializeLayout(object sender, LayoutEventArgs e)
        {
            foreach (UltraGridColumn c in e.Layout.Bands[0].Columns)
            {
                c.Header.RowLayoutColumnInfo.OriginY = 1;
            }
            ColumnHeader A = new ColumnHeader(true);
            A.Caption = "People";
            A.RowLayoutColumnInfo.OriginY = 0;
            A.RowLayoutColumnInfo.SpanX = 3;
            A.Key = "People";
            e.Layout.Bands[0].HeaderLayout.Add(A);
            OrignHedersOptions = e.Layout.Bands[0].HeaderLayout.CopyFrom(e.Layout.Bands[0].HeaderLayout);
        }

       
        void MakeHiddenColumn(UltraWebGrid ultraWebGrid, string key, HeadersCollection OrignHedersOptions)
        {
            if (!(ultraWebGrid.Bands[0].Columns.FromKey(key).Hidden))
            {
                ultraWebGrid.Bands[0].Columns.FromKey(key).Hidden = true;
                foreach (ColumnHeader origHead in OrignHedersOptions)
                {
                    if ((origHead.RowLayoutColumnInfo.SpanX > 1) &&
                        (origHead.RowLayoutColumnInfo.OriginX + origHead.RowLayoutColumnInfo.SpanX - 1 >= ultraWebGrid.Bands[0].Columns.FromKey(key).Index))
                    {
                        foreach (ColumnHeader curHead in ultraWebGrid.Bands[0].HeaderLayout)
                        {
                            if (curHead.Key == origHead.Key)
                            {                               
                                if (origHead.RowLayoutColumnInfo.OriginX == ultraWebGrid.Bands[0].Columns.FromKey(key).Index)
                                {
                                    curHead.RowLayoutColumnInfo.OriginX = ultraWebGrid.Bands[0].Columns.FromKey(key).Index + 1;
                                }
                                curHead.RowLayoutColumnInfo.SpanX--;
                            }
                        }
                    }
                }
            }
        }
       
       
        void MakeAnHiddenColumn(UltraWebGrid ultraWebGrid, string key, HeadersCollection OrignHedersOptions)
        {
            if (ultraWebGrid.Bands[0].Columns.FromKey(key).Hidden)
            {
                ultraWebGrid.Bands[0].Columns.FromKey(key).Hidden = false;
                foreach (ColumnHeader origHead in OrignHedersOptions)
                {
                    if ((origHead.RowLayoutColumnInfo.SpanX > 1) &&
                        (origHead.RowLayoutColumnInfo.OriginX + origHead.RowLayoutColumnInfo.SpanX - 1 >= ultraWebGrid.Bands[0].Columns.FromKey(key).Index) &&
                        (origHead.Caption != key))
                    {
                        foreach (ColumnHeader curHead in ultraWebGrid.Bands[0].HeaderLayout)
                        {
                            if (curHead.Key == origHead.Key)
                            {                               
                                if (origHead.RowLayoutColumnInfo.OriginX == ultraWebGrid.Bands[0].Columns.FromKey(key).Index)
                                {
                                    curHead.RowLayoutColumnInfo.OriginX = ultraWebGrid.Bands[0].Columns.FromKey(key).Index;
                                }
                                curHead.RowLayoutColumnInfo.SpanX++;
                            }
                        }
                    }
                }
            }
        }


        /// <summary>
        /// Hidden Column
        /// </summary>       
        protected void WebImageButton3_Click(object sender, ButtonEventArgs e)
        {
            this.MakeHiddenColumn(this.UltraWebGrid1, WebTextEditor1.Text, this.OrignHedersOptions);
        }

        /// <summary>
        /// Show Column
        /// </summary>       
        protected void WebImageButton4_Click(object sender, ButtonEventArgs e)
        {
            this.MakeAnHiddenColumn(this.UltraWebGrid1, WebTextEditor1.Text, this.OrignHedersOptions);
        }
    }
}

 

*.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyPage.aspx.cs" Inherits="WebApplication1.MyPage" %>

<%@ Register Assembly="Infragistics4.Web.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<%@ Register Assembly="Infragistics4.Web.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.Web.UI" TagPrefix="ig" %>
<%@ Register Assembly="Infragistics4.WebUI.WebDataInput.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.WebUI.WebDataInput" TagPrefix="igtxt" %>
<%@ Register assembly="Infragistics4.WebUI.UltraWebGrid.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.UltraWebGrid" tagprefix="igtbl" %>
<%@ Register assembly="Infragistics4.WebUI.UltraWebGrid.DocumentExport.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.UltraWebGrid.DocumentExport" tagprefix="igtbldocexp" %>
<%@ Register assembly="Infragistics4.WebUI.UltraWebGrid.ExcelExport.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.UltraWebGrid.ExcelExport" tagprefix="igtblexp" %>
<%@ Register assembly="Infragistics4.Web.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.EditorControls" tagprefix="ig" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>       
        <igtxt:WebImageButton ID="WebImageButton3" runat="server"
            onclick="WebImageButton3_Click" Text="Hidden Column">
        </igtxt:WebImageButton>
        <igtxt:WebImageButton ID="WebImageButton4" runat="server"
            onclick="WebImageButton4_Click" Text="Show Column">
        </igtxt:WebImageButton>
        <ig:WebTextEditor ID="WebTextEditor1" runat="server" Text="index">
        </ig:WebTextEditor>
        <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Height="647px"
            Width="448px" oninitializelayout="UltraWebGrid1_InitializeLayout">
            <displaylayout allowcolsizingdefault="Free" allowcolumnmovingdefault="OnServer"
                allowdeletedefault="Yes" allowsortingdefault="OnClient"
                allowupdatedefault="Yes" autogeneratecolumns="False"
                bordercollapsedefault="Separate" headerclickactiondefault="SortMulti"
                name="UltraWebGrid1" rowheightdefault="20px" rowselectorsdefault="No"
                selecttyperowdefault="Extended" stationarymargins="Header"
                stationarymarginsoutlookgroupby="True" tablelayout="Fixed" version="4.00"
                viewtype="OutlookGroupBy" ColFootersVisibleDefault="Yes">
                <framestyle backcolor="Window" bordercolor="InactiveCaption"
                    borderstyle="Solid" borderwidth="1px" font-names="Microsoft Sans Serif"
                    font-size="8.25pt" height="647px" width="448px">
                </framestyle>
                <pager minimumpagesfordisplay="2">
                    <PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
                    <borderdetails colorleft="White" colortop="White" widthleft="1px"
                        widthtop="1px" />
                    </PagerStyle>
                </pager>
                <editcellstyledefault borderstyle="None" borderwidth="0px">
                </editcellstyledefault>
                <footerstyledefault backcolor="LightGray" borderstyle="Solid" borderwidth="1px">
                    <borderdetails colorleft="White" colortop="White" widthleft="1px"
                        widthtop="1px" />
                </footerstyledefault>
                <headerstyledefault backcolor="LightGray" borderstyle="Solid"
                    horizontalalign="Left">
                    <borderdetails colorleft="White" colortop="White" widthleft="1px"
                        widthtop="1px" />
                </headerstyledefault>
                <rowstyledefault backcolor="Window" bordercolor="Silver" borderstyle="Solid"
                    borderwidth="1px" font-names="Microsoft Sans Serif" font-size="8.25pt">
                    <padding left="3px" />
                    <borderdetails colorleft="Window" colortop="Window" />
                </rowstyledefault>
                <groupbyrowstyledefault backcolor="Control" bordercolor="Window">
                </groupbyrowstyledefault>
                <groupbybox>
                    <boxstyle backcolor="ActiveBorder" bordercolor="Window">
                    </boxstyle>
                </groupbybox>
                <addnewbox hidden="False">
                    <boxstyle backcolor="Window" bordercolor="InactiveCaption" borderstyle="Solid"
                        borderwidth="1px">
                        <borderdetails colorleft="White" colortop="White" widthleft="1px"
                            widthtop="1px" />
                    </boxstyle>
                </addnewbox>
                <activationobject bordercolor="" borderwidth="">
                </activationobject>
                <filteroptionsdefault FilterUIType="HeaderIcons" AllowRowFiltering="OnServer">
                    <filterdropdownstyle backcolor="White" bordercolor="Silver" borderstyle="Solid"
                        borderwidth="1px" customrules="overflow:auto;"
                        font-names="Verdana,Arial,Helvetica,sans-serif" font-size="11px" height="300px"
                        width="200px">
                        <padding left="2px" />
                    </filterdropdownstyle>
                    <filterhighlightrowstyle backcolor="#151C55" forecolor="White">
                    </filterhighlightrowstyle>
                    <filteroperanddropdownstyle backcolor="White" bordercolor="Silver"
                        borderstyle="Solid" borderwidth="1px" customrules="overflow:auto;"
                        font-names="Verdana,Arial,Helvetica,sans-serif" font-size="11px">
                        <padding left="2px" />
                    </filteroperanddropdownstyle>
                </filteroptionsdefault>
            </displaylayout>
            <bands>
                <igtbl:UltraGridBand>
                    <Columns>
                        <igtbl:UltraGridColumn BaseColumnName="index" DataType="System.Int32"
                            Key="index">
                            <Header Caption="index">
                            </Header>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="name" Key="name">
                            <Header Caption="name">
                                <RowLayoutColumnInfo OriginX="1" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="1" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="sex" DataType="System.Boolean" Key="sex"
                            Type="CheckBox">
                            <Header Caption="sex">
                                <RowLayoutColumnInfo OriginX="2" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="2" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                    </Columns>
                    <addnewrow view="NotSet" visible="NotSet">
                    </addnewrow>
                </igtbl:UltraGridBand>
            </bands>
        </igtbl:UltraWebGrid>
        <ig:WebScriptManager ID="WebScriptManager1" runat="server">
        </ig:WebScriptManager>       
    </div>  
    </form>
</body>
</html>

I hope that you will help in resolving this issue. I would be glad if you suggest another solution to this problem. Thank you!