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
745
How to Hide the Columns In Web Hierarchy Grid
posted

Dear All..

I am using ultraweb 9.2 version... i am binding my grid manually. i dont want to display first column in my grid.

Below am giving my code so plz suggest me where i went wrong..

 protected void Page_Load(object sender, EventArgs e)

    {

        BindGrid();       

    }   

    protected void WebHierarchicalDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)

    {

        // don't show the arrow for the last level

        if (((ContainerGridRecord)e.Row).Level < 2)

            ((ContainerGridRecord)e.Row).IsEmptyParent = true;

    }

    protected void WebHierarchicalDataGrid1_RowIslandsPopulating(object sender, Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)

    {

        //Cancel the default automatic load on demand operation

        e.Cancel = true;

        switch (e.Row.Level)

        {

            case 0:

                BindSecondLevel(e);

                break;

            case 1:

                BindThirdLevel(e);

                break;

        }

 

    }

    protected void WebHierarchicalDataGrid1_PreRender(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            foreach (ContainerGridRecord row in WebHierarchicalDataGrid1.GridView.Rows)

            {

                row.IsEmptyParent = true;

            }

        }

    }

 

    private void BindGrid()

    {

        try

        {

            DataSet ds = new DataSet();

            if (Session["user"] != null)

            {

                ds = new ComplianceReportBO().GetFrameWorkNames();

                List<Sample> list = new List<Sample>();

                foreach (DataRow dr in ds.Tables[0].Rows)

                {

                    list.Add(new Sample { FrameworkName = dr.ItemArray[1].ToString(), ID = Int64.Parse(dr.ItemArray[0].ToString()) });

                }               

                WebHierarchicalDataGrid1.DataSource = list;

 

            }

        }

        catch (Exception)

        {

 

            throw;

        }      

 

    }

 

    private void BindSecondLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)

    {

        try

        {

            // Get the data key

            long key = (long)e.Row.DataKey[0];

 

            DataSet Child = new DataSet();

            Child = new ComplianceReportBO().GetFrameWorkChildNames(key);

            Child.Tables[0].TableName = "Child";

 

            // Create Container Grid

            ContainerGrid childGrid = new ContainerGrid();

            e.Row.RowIslands.Add(childGrid);          

 

            // Bind Grid

            childGrid.DataKeyFields = "Id";

            childGrid.Level = 1;

            childGrid.DataSource = Child;           

            childGrid.DataBind();

        }

        catch (Exception)

        {

 

            throw;

        }

 

 

    }

 

    private void BindThirdLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)

    {

        try

        {

            // Get the data key

            long key = (long)e.Row.DataKey[0];

            DataSet grandChild = new DataSet();

            grandChild = new ComplianceReportBO().GetFrameWorkChildNames(key);

            grandChild.Tables[0].TableName = "grandChild";

 

            // Create Container Grid

            ContainerGrid childGrid = new ContainerGrid();

            e.Row.RowIslands.Add(childGrid);

 

            // Bind Grid

            childGrid.DataKeyFields = "Id";

            childGrid.Level = 2;

            childGrid.DataSource = grandChild;            

            childGrid.DataBind();

 

        }

        catch (Exception)

        {

 

            throw;

        }

 

 

    }

Regards

Naag

  • 12679
    Verified Answer
    posted

    Hi Naag,

     

    As far as I can see you are relying on AutoGeneratedColumns property of the grid to generate its columns based on the DataSource. In such case you can try to attach your handler to ContainerGrid intializeRow event and then access the column there and set its property Hidden to true. 

     

    void WebHierarchicalDataGrid1_InitializeRow(object sender,

                        Infragistics.Web.UI.GridControls.RowEventArgs e)

        {

            if (e.Row.Index == 1)

            {

                e.Row.Items[0].Column.Hidden = true;

            }

        }