Removing a Column from Telerik RadGrid at Runtime

by Tom Hundley 11. June 2010 07:13

If you need to remove a column from a Telerik RadGrid at runtime, subscribe to the grid's DataBound event, find the column by its unique name, and set its display property to false.  This is the correct way to do this without breaking the filter functionality.  For a long time I was subscribing to the grid's ItemDataBound event and hiding each dataitem for the column- only now did I realize that the filter was broken by doing it that way.

 

Example:

protected void rgPartDispositionHistory_DataBound(object sender, EventArgs e)
    {
        rgPartDispositionHistory.MasterTableView.Columns
.FindByUniqueName("PeopleSoftId").Display = isTwtc; }
 

Tom Hundley
Elegant Software Solutions, LLC

Tags: , ,

ASP.Net | Telerik

Removing Horizontal Scroll from Telerik RadComboBox

by Tom Hundley 11. June 2010 07:12

If you have a rad combo box and the dropdown width is larger than the width, you'll get the annoying horizontal scroll bars.  You can fix this in css by using the "!important" tag.  Thanks to Telerik support for this fix:

 

.rcbScroll
{
    overflow-y: auto;
    overflow-x: hidden !important;
}

 

Tom Hundley
Elegant Software Solutions, LLC

 

Reference:
http://www.telerik.com/community/forums/aspnet-ajax/combobox/horizontal-scroll-problem.aspx

Tags: , ,

ASP.Net | Telerik

Hiding expand/collapse columns with Telerik RadGrid

by Tom Hundley 19. May 2010 08:23

Often times when using nested grids, you may desire to hide the expand/collapse button if there are no child items.  This is very easy to do, although it’s not as intuitive as you might think.  This example will show you how to accomplish this task  using a Telerik RadGrid for ASP.Net Ajax.

 

1.  First, subscribe to the PreRender event of the Grid control.

2.  Loop through the GridNestedViewItems.

3.  Apply your visibility logic.

 

    protected void rgParts_PreRender(object sender, EventArgs e)
    {
        GridItem[] nestedViewItems = rgParts.MasterTableView.GetItems(GridItemType.NestedView);
        foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
        {
            foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
            {
                if (((Foo)nestedView.ParentItem.DataItem).Prop1 == "DontShowExpandColmn")
                {
                    TableCell cell = nestedView.ParentItem["ExpandColumn"];
                    cell.Controls[0].Visible = false;
                    nestedViewItem.Visible = false;
                }
            }
        }
    }
 

Tom Hundley
Elegant Software Solutions, LLC

Tags: , ,

ASP.Net | Telerik