Show/Hide columns in SelectedIndexChanged event of imbedded RadComboBox

5 posts, 1 answers
  1. Jan Pfeffer
    Jan Pfeffer avatar
    55 posts
    Member since:
    Aug 2006

    Posted 15 Jan 2013 Link to this post

    Hey at Telerik

    I have tried for hours now to show/hide columns depending on the selected index of an in a RadGrid imbedded RadComboBox.

    The problem is that if i try to rebind in the SelectedIndexChanged event of the imbedded RadComboBox the Inserted Item is disposed.

    If i don't rebind the visibility of the columns are not refreshed.

    protected void rgvEgenskaber_PreRender(object sender, EventArgs e)
        {
            if (this.rgvEgenskaber.MasterTableView.IsItemInserted || this.rgvEgenskaber.EditItems.Count > 0)
            {
                GridEditableItem gridEditableItem = null;
                if (this.rgvEgenskaber.MasterTableView.IsItemInserted)
                    gridEditableItem = this.rgvEgenskaber.MasterTableView.GetInsertItem();
                else
                    gridEditableItem = this.rgvEgenskaber.EditItems[0] as GridEditableItem;
                DLDataContext dLDataContext = new DLDataContext();
                Egenskab egenskab = dLDataContext.Egenskabs.First(eg => eg.Egenskabid.Equals(Guid.Parse(((RadComboBox)((GridDataItem)gridEditableItem)["EgenskabID"].Controls[1]).SelectedValue)));
                //if (gridEditableItem.DataItem != null)
                //{
                this.rgvEgenskaber.MasterTableView.Columns.OfType<GridColumn>().Where(c => c.UniqueName.Equals("Valglistevaerdi") || c.UniqueName.Equals("Decimalvaerdi") || c.UniqueName.Equals("Heltalsvaerdi")).ToList().ForEach(c => c.Visible = false);
                switch (egenskab.Type)
                {
                    case "H":
                        this.rgvEgenskaber.MasterTableView.GetColumn("Heltalsvaerdi").Visible = true;
                        break;
                    case "D":
                        this.rgvEgenskaber.MasterTableView.GetColumn("Decimalvaerdi").Visible = true;
                        break;
                    case "V":
                        this.rgvEgenskaber.MasterTableView.GetColumn("Valglistevaerdi").Visible = true;
                        break;
                    default:
                        break;
                }
            }
        }
    protected void rcbEgenskabID_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            this.rgvEgenskaber.MasterTableView.Rebind();
      }

     

    protected void rgvEgenskaber_ItemCommand(object source, GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case RadGrid.InitInsertCommandName:
                    e.Canceled = true;
                    if (Request.QueryString["elementType"] != null && Request.QueryString["elementId"] != null)
                    {
                        string elementType = Request.QueryString["elementType"];
                        string elementId = Request.QueryString["elementId"];
                        DLContext.DLDataContext dLDataContext = new DLDataContext();
                        Bestemmelse bestemmelse = dLDataContext.Bestemmelses.First(b => b.Bestemmelseid.Equals(Guid.Parse(elementId)));
                        Egenskab egenSkab = dLDataContext.Egenskabs.First();
                        Egenskabsforklaring egenskabsforklaring = dLDataContext.Egenskabsforklarings.First();
                        if (!e.Item.OwnerTableView.IsItemInserted)
                            e.Item.OwnerTableView.InsertItem(new Egenskabsvaerdi() { Egenskabsvaerdiid = Guid.NewGuid(),  Egenskab = egenSkab, Egenskabsforklaring = egenskabsforklaring, Bestemmelse = bestemmelse });
                    }
                    break;
                case RadGrid.PageCommandName:
                    break;
                default:
                    break;
            }
        }

     

    I hope you can help me with this problem.

    Sincerly Jan

  2. Answer
    Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 18 Jan 2013 Link to this post

    Hello Jan,

    Please try to hide the columns by using display set to "none"  instead of the "visible" property. In this case calling Rebind() would not be needed. Give this a try and let me know how it goes.

    Regards,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jan Pfeffer
    Jan Pfeffer avatar
    55 posts
    Member since:
    Aug 2006

    Posted 05 Feb 2013 Link to this post

    Hey Maria

    The only thing i can do on the GridColumn under the PreRender event is set the Display property, besides the Visible property.
    Setting the Display property doesn't work either.
    Below is my PreRender event method.

    Sincerly

    Jan
    protected void rgvEgenskaber_PreRender(object sender, EventArgs e)
        {
            if (this.rgvEgenskaber.MasterTableView.IsItemInserted || this.rgvEgenskaber.EditItems.Count > 0)
            {
                GridEditableItem gridEditableItem = null;
                if (this.rgvEgenskaber.MasterTableView.IsItemInserted)
                    gridEditableItem = this.rgvEgenskaber.MasterTableView.GetInsertItem();
                else
                    gridEditableItem = this.rgvEgenskaber.EditItems[0] as GridEditableItem;
                DLDataContext dLDataContext = new DLDataContext();
                Guid guid = Guid.Empty;
                if (Guid.TryParse(((RadComboBox)((GridDataItem)gridEditableItem)["EgenskabID"].Controls[1]).SelectedValue, out guid))
                {
                    Egenskab egenskab = dLDataContext.Egenskabs.First(eg => eg.Egenskabid.Equals(guid));
                    this.rgvEgenskaber.MasterTableView.Columns.OfType<GridColumn>().Where(c => c.UniqueName.Equals("Egenskabsdomaeneid") || c.UniqueName.Equals("Decimalvaerdi") || c.UniqueName.Equals("Heltalsvaerdi")).ToList().ForEach(c => c.Visible = false);
                    switch (egenskab.Type)
                    {
                        case "H":
                            this.rgvEgenskaber.MasterTableView.GetColumn("Heltalsvaerdi").Display = this.rgvEgenskaber.MasterTableView.GetColumn("Heltalsvaerdi").Visible = true;
                            break;
                        case "D":
                            this.rgvEgenskaber.MasterTableView.GetColumn("Decimalvaerdi").Display = this.rgvEgenskaber.MasterTableView.GetColumn("Decimalvaerdi").Visible = true;
                            break;
                        case "V":
                            this.rgvEgenskaber.MasterTableView.GetColumn("Egenskabsdomaeneid").Display = this.rgvEgenskaber.MasterTableView.GetColumn("Egenskabsdomaeneid").Visible = true;
                            break;
                        default:
                            break;
                    }
                }
            }
        }
  5. Jan Pfeffer
    Jan Pfeffer avatar
    55 posts
    Member since:
    Aug 2006

    Posted 05 Feb 2013 Link to this post

    Hey Maria

    Seems like it worked if only the Diaplay property is used.

    Sorry for the inconvenience.

    Sincerly

    Jan
  6. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 07 Feb 2013 Link to this post

    Hi Jan,

    Thank you for updating us on this thread. I'm glad the provided suggestion helps.

    Do not hesitate to contact Telerik Support in case any other issues appear.

    Kind regards,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017