This is a migrated thread and some comments may be shown as answers.

Remove Options From Radgrid Header Context Menu

11 Answers 502 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 07 Jan 2009, 09:44 PM
I just updated to the new Q3 release of telerik controls. I am utilizing the header context menu attribute of radgrid by setting  EnableHeaderContextMenu="true". Some of my grids contain GridTemplateColumns which contain controls such as image buttons, etc... I don't want these types of columns to show up in the header context menu. I have been unable to find a way to stop certain columns from being added to the header context menu of a radgrid. Is this possible? I would assume that there would be some kind of attribute on a column I can set to not show in headercontextmenu. I found that I can catch the click using OnColumnContextMenu but at that point I have been unable to get a handle on the headercontextmenu of the grid to remove items/options. Thanks in advance for any help...

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 08 Jan 2009, 11:45 AM
Hi Ryan,

I would suggest you to hide the unwanted menu item in the OnClientItemOpening client event of the HeaderContextMenu.

ASPX:
<HeaderContextMenu   OnClientItemOpening="OnClientItemOpening"  > 
                   </HeaderContextMenu> 

JS:
<script type="text/javascript"
  function OnClientItemOpening(menu, args) 
   { 
     var item = args.get_item(); 
     item.get_items().getItem(0).get_element().style.display="none";    
    } 
</script> 

Regards
Shinu.
0
Ryan
Top achievements
Rank 1
answered on 08 Jan 2009, 09:56 PM
Thank you for your speedy reply. The problem with hiding these menu options in the OnClientItemOpening event would be that u are executing that script every time the columns menu is expanded. I am surprised to see that this is not built in functionality. The best solution I could come up with is to hook into the PreRender of the header context menu as I did below:

protected void Grid_Load(object sender, EventArgs e)
 {
            Grid.HeaderContextMenu.PreRender += new EventHandler(GridHeaderContextMenu_PreRender);
 }

Next I created a generic function that I can hand my rad menu items and a hash of the unique column names of the columns I don't want in the menu. Obviously I have to remove the menu items I don't want after the menu is built being that this functionality is not built into the grid and I am hooking in on prerender. The unique column name is the only unique identifier I could find in sifting through the data structure of the header context menu so that was what I used to locate my columns. Below is the static function I created and the call to that function with the dataset and name to remove in a hashtable for constant lookup.

The helper function:

        public static void RemoveHeaderContextMenuColumnsByUniqueName(Hashtable uniqueNames, IList<RadMenuItem> menuItems)
        {
            for (int topItemIndex = 0; topItemIndex <= menuItems.Count - 1; topItemIndex++)
            {
                if (menuItems[topItemIndex].Text == "Columns")
                {
                    var lowerMenuItemsCount = menuItems[topItemIndex].Items.Count;
                    for (int lowerItemIndex = lowerMenuItemsCount - 1; lowerItemIndex >= 0; lowerItemIndex--)
                    {
                        string strName = menuItems[topItemIndex].Items[lowerItemIndex].Value;
                        string strColName = strName.Split('|')[1];
                        if (uniqueNames[strColName] != null)
                        {
                            menuItems[topItemIndex].Items.RemoveAt(lowerItemIndex);
                        }
                    }
                }
            }
        }
 

And the function call from PreRender:

protected void ProductsGridHeaderContextMenu_PreRender(object sender, EventArgs e)
{
            RadGridUtility.RemoveHeaderContextMenuColumnsByUniqueName(_columnsToHide,Grid.HeaderContextMenu.GetAllItems()); 
}

Please let me know if there is a more optimal way.
0
sean
Top achievements
Rank 1
answered on 06 Dec 2010, 04:59 PM

thanks for that code  :-)  I had a similar requirement and the code sample was very helpful.  The lack of an easy and/or markup based way to exclude a column from being hidden is very inconvenient.  Happily though, the objects are open, and the methods are there.
I wanted to offer up the suggestions below.  
Basically, I compressed the first loop with menuItems.First linq search.  And I used their "FindItem" method to search for the real target item, within the Columns ItemCollection.  The test inside is basically the same .Split test from the original code.

        public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
        {

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
                        targetControl.Enabled = false;
                    }

                }
            }

        public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
        {

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
                        targetControl.Enabled = false;
                    }

                }
            }
        public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
        {

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
                        targetControl.Enabled = false;
                    }

                }
            }
        public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
        {

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
                        targetControl.Enabled = false;
                    }

                }
            }
        public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
        {

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
                        targetControl.Enabled = false;
                    }

                }
            }
 

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
        public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
        {

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
                        targetControl.Enabled = false;
                    }

                }
            }

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
{
 
    string outerMenuName = "Columns";
    RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
      
    if (col_rmi != null && col_rmi.Count() > 0)
    {
        foreach (string targetName in uniqueNames)
        {
            RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
            if (targetControl != null)
            {
                targetControl.Enabled = false;
            }
 
        }
    }

        public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
        {

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
                        targetControl.Enabled = false;
                    }

                }
            }
        public static void RemoveHeaderContextMenuColumnsByUniqueName(HashSet<string> uniqueNames, IList<RadMenuItem> menuItems)
        {

            string outerMenuName = "Columns";
            RadMenuItemCollection col_rmi = menuItems.First<RadMenuItem>(rmi => rmi.Text == outerMenuName).Items;
             
            if (col_rmi != null && col_rmi.Count() > 0)
            {
                foreach (string targetName in uniqueNames)
                {
                    RadMenuItem targetControl = col_rmi.FindItem(rmi => rmi.Value.Split('|').Last() == targetName);
                    if (targetControl != null)
                    {
                        targetControl.Enabled = false;
                    }

                }
            }
0
Vishu
Top achievements
Rank 1
answered on 25 Jun 2014, 08:31 PM
Have same sort of issue with column hide and un-hide. On page load making column.Display=False to hide column in rad grid but the issue is while un-checking hidden columns JS could not able to find display=false columns and gives JS error(Image-1).

Secondly, I tried to set column.Visible=false on page load but visible=false columns does not appear in context menu list as context menu only lists visible=true columns(Image-2) .

Please suggest how to hide and un-hide column via context menu. (Have attached code snippet of function to assign column properties on Page_Load)
0
Shinu
Top achievements
Rank 1
answered on 26 Jun 2014, 05:22 AM
Hi Vishu,

When you set visible property to false, the columns will not be accessible in client side , serverside or ContextMenu. If you want to hide a column set its Display property as false. Please take a look at the sample code snippet, I have hidden the columns but its accessible in the Client side as well as in the ContextMenu. If this doesn't help, please paste your full code snippet.

ASPX:
<telerik:RadGrid ID="rgridSample" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"EnableHeaderContextMenu="true" AllowPaging="true">
   <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="CustomerID" DataField="CustomerID" HeaderText="CustomerID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipVia" HeaderText="ShipVia" UniqueName="ShipVia" Display="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="OrderDate" DataField="OrderDate" HeaderText="OrderDate">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Freight" HeaderText="Freight" UniqueName="Freight" Display="false">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<input id="btnColumns" type="button" onclick="GetColumnNames();" value="Show Columns" />

JS:
<script type="text/javascript">
    function GetColumnNames() {
        var grid = $find("<%=RadGrid1.ClientID %>");
        var columnCount = grid.get_masterTableView().get_columns().length;
        for (var i = 0; i < columnCount; i++) {
            var UniqueName = grid.get_masterTableView().get_columns()[i].get_uniqueName();
            alert(UniqueName)
        }
    }
</script>

Thanks,
Shinu
0
Vishu
Top achievements
Rank 1
answered on 26 Jun 2014, 02:19 PM
Thanks Shinu,

My main column assignment logic is at server side and if I uses column.display=true then getting JS error (mentioned in previous post) while checking columns in context menu to include them back in grid. Below is the code snippet. In below code behind function, assigning column order-index, width and hidden columns preferences based on users and saved in database. 

.Aspx code:
<telerik:RadGrid ID="gridItemsSearch" runat="server" PageSize="19" AllowPaging="true" HeaderStyle-Font-Underline="true" AllowCustomPaging="true" OnPageIndexChanged="gridItemsSearch_PageIndexChanged" 
                        AutoGenerateColumns="False" Skin="Office2007" OnItemCommand="gridItemsSearch_OnItemCommand" Visible="true" OnSortCommand="gridItemsSearch_SortCommand"  EnableHeaderContextMenu="true"
                       OnNeedDataSource="gridItemsSearch_NeedDataSource" ExportSettings-FileName="ItemParts" OnItemDataBound="gridItemsSearch_ItemDataBound" 
                       OnPreRender="gridItemsSearch_PreRender"  AllowSorting="true" CellPadding="2" ShowFooter="false" ExportSettings-ExportOnlyData="false">                            
                       <PagerStyle Mode="NextPrevAndNumeric" Position="Top" ></PagerStyle>
                       <MasterTableView ShowHeadersWhenNoRecords="true" AllowSorting="true" AllowMultiColumnSorting="false" AllowNaturalSort="true" UseAllDataFields="false" ItemStyle-Height="5px" EnableColumnsViewState="true" TableLayout="Fixed" 
                           DataKeyNames="ItemNumber">                                
                           <Columns>
                               <telerik:GridTemplateColumn SortExpression="ItemNumber" DataField="ItemNumber" HeaderText=""
                                   UniqueName="ChkItemNumber" HeaderStyle-Width="30px">
                                   <ItemTemplate>
                                       <asp:ImageButton ID="imgpickItem" runat="server" ToolTip="Click to add to Kit Contents" ImageUrl="~/images/basket_add.png" 
                                           CommandName="Select" />
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>
                               <%-- Newly Added columns are following --%>
                                <telerik:GridBoundColumn DataField="Branch" HeaderText="Branch" SortExpression="Branch"
                                   UniqueName="BranchId" ItemStyle-HorizontalAlign="Left" />
                                <telerik:GridBoundColumn DataField="BranchDesc" HeaderText="Branch Description" SortExpression="BranchDesc"
                                   UniqueName="BranchName" ItemStyle-HorizontalAlign="Left"/>
                               <%-- Newly added columns adding ends --%>
                               <telerik:GridBoundColumn DataField="ItemNumber" HeaderText="Item ID" 
                                   UniqueName="ItemNumber" ItemStyle-HorizontalAlign="Left" SortExpression="ItemNumber"/>                                   
                               <telerik:GridBoundColumn DataField="ItemDescription" HeaderText="Item Description" UniqueName="ItemDescription"
                                   ItemStyle-HorizontalAlign="Left" SortExpression="ItemDescription" />
                               <telerik:GridBoundColumn DataField="Group" UniqueName="Group" Visible="false" />
                               <telerik:GridBoundColumn DataField="Available" HeaderText="Available"  SortExpression="Available" DataType="System.Double" 
                                   ItemStyle-HorizontalAlign="Center" UniqueName="Available" />
                               
                               <telerik:GridBoundColumn DataField="READYFORRENT_QTY" HeaderText="Assets Ready for Rent"  DataType="System.Double" 
                                   ItemStyle-HorizontalAlign="Center" UniqueName="READYFORRENT_QTY" SortExpression="READYFORRENT_QTY" />
                               
                               <telerik:GridBoundColumn DataField="Allocated" HeaderText="Allocated" SortExpression="Allocated"
                                   ItemStyle-HorizontalAlign="Center" UniqueName="Allocated" Visible="false"/>
                               
                               <telerik:GridTemplateColumn DataField="Allocated" HeaderText="Allocated" UniqueName="AllocatedPopup" SortExpression="Allocated"  ItemStyle-HorizontalAlign="Center">
                                   <ItemTemplate>                                                        
                                       <asp:LinkButton ToolTip="Allocated Quantity" runat="server" ID="lnkSelectAllocated" OnClick="BtnSelectItemAllocationData_Click" Visible="true" Text='<%# Eval("Allocated") %>' />
                                       <asp:Label ID="lblAllocated" runat="server" Visible="false" Text='<%# Eval("Allocated") %>' />
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>                                   

                                <telerik:GridTemplateColumn DataField="QtyOnHand" HeaderText="On Hand" UniqueName="OnHand"  ItemStyle-HorizontalAlign="Center" SortExpression="QtyOnHand">
                                   <ItemTemplate>
                                           <asp:LinkButton Text='<%# Eval("QtyOnHand") %>' runat="server"  ID="BtnSelectItemLocation" OnClick="BtnSelectItemLocation_Click" Visible="true" ToolTip="Click to see item storage location"/>
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>

                               <telerik:GridBoundColumn DataField="OnOrder" HeaderText="On Order"  SortExpression="OnOrder"
                                   ItemStyle-HorizontalAlign="Center" UniqueName="OnOrder" />
                                <telerik:GridBoundColumn DataField="AverageCost" HeaderText="Average Cost" DataType="System.Double" DefaultInsertValue="0.0" 
                                   ItemStyle-HorizontalAlign="Center" UniqueName="AverageCost" SortExpression="AverageCostActualValue"/>
                                <telerik:GridBoundColumn DataField="SixMonthUsage" HeaderText="6 Month Usage" SortExpression="SixMonthUsage"
                                   ItemStyle-HorizontalAlign="Center" UniqueName="SixMonthUsage"/>

                                 <telerik:GridTemplateColumn DataField="TwelveMonthUsage" HeaderText="12 Month Usage" UniqueName="TwelveMonthUsage" SortExpression="TwelveMonthUsage" ItemStyle-HorizontalAlign="Center">
                                   <ItemTemplate>                                                        
                                       <asp:LinkButton ToolTip="12 Month Usage" runat="server" ID="lnkSelect12MonUsage" OnClick="BtnSelectItem12MonUsage_Click" Visible="true" Text='<%# Eval("TwelveMonthUsage") %>' />
                                       <asp:Label ID="lbl12MonUsage" runat="server" Visible="false" Text='<%# Eval("TwelveMonthUsage") %>' />
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>                                      

                               <telerik:GridBoundColumn DataField="UnitOfMeasure" HeaderText="Standard UOM" 
                                   ItemStyle-HorizontalAlign="Left" UniqueName="UnitOfMeasure" SortExpression="UnitOfMeasure" />
                                                            
                                <telerik:GridTemplateColumn DataField="VendorName" HeaderText="Preferred Vendor" UniqueName="VendorName" ItemStyle-HorizontalAlign="Left" SortExpression="VendorName" >
                                   <ItemTemplate>
                                        <asp:LinkButton ToolTip="Click to see additional vendors" runat="server" ID="BtnSelectVendor" OnClick="BtnSelectVendor_Click" Visible="true" Text='<%# Eval("VendorName") != "" ? Eval("VendorName") : "" %>' />                                             
                                   </ItemTemplate>
                                 </telerik:GridTemplateColumn>

                                <telerik:GridBoundColumn DataField="OEMPartNo" HeaderText="OEM Part #" UniqueName="OEMPart" SortExpression="OEMPartNo"
                                   ItemStyle-HorizontalAlign="Left" />
                                                             
                                 <telerik:GridTemplateColumn DataField="OEM" HeaderText="OEM" UniqueName="OEM" ItemStyle-HorizontalAlign="Center" SortExpression="OEM">
                                   <ItemTemplate>
                                           <asp:LinkButton ToolTip="Click to see additional manufacturers" runat="server" ID="BtnSelectItemOEMData" OnClick="BtnSelectItemOEMData_Click" Visible="true" Text='<%# Eval("OEM") != "" ? Eval("OEM") : "" %>'  />                                                 
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>                                     
                                                              
                               <telerik:GridBoundColumn DataField="ReorderPoint" HeaderText="Reorder Point" 
                                   ItemStyle-HorizontalAlign="Center" UniqueName="ReorderPoint" SortExpression="ReorderPoint" />                                                                   
                              
                                <telerik:GridTemplateColumn HeaderText="Critical Item" ItemStyle-HorizontalAlign="Center" UniqueName="CriticalItem" SortExpression="CriticalItem">
                                   <ItemTemplate>
                                           <asp:CheckBox ID="BtnSelectCriticalItem" runat="server" Enabled="false"  Checked='<%# Eval("CriticalItem").ToString()  == "Y" ? true : false %>' />
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>

                                <telerik:GridBoundColumn DataField="VRMSFullCode" HeaderText="VMRS Code"  SortExpression="VRMSFullCode"
                                   ItemStyle-HorizontalAlign="Left" UniqueName="VRMSFullCode"/>
                               <telerik:GridBoundColumn DataField="IsPMKitItem" HeaderText="PM Kit"  SortExpression="IsPMKitItem" Visible="false" 
                                   ItemStyle-HorizontalAlign="Left" UniqueName="IsPMKitItem"/>
                                <telerik:GridBoundColumn DataField="CoreValue" HeaderText="Core Value"  
                                   ItemStyle-HorizontalAlign="Left" UniqueName="CoreValue" SortExpression="CoreValue" />
                                <telerik:GridTemplateColumn DataField="PrintBarCode" HeaderText="Print Barcode" UniqueName="PrintbarcodeLinkLevel1" ItemStyle-HorizontalAlign="Left">                                     
                                   <ItemTemplate>                                                                
                                       <asp:ImageButton ID="PrintbarcodeLinkInventory" runat="server"  ImageUrl="~/Images/Print.png" ToolTip="Print Barcode"/>
                                   </ItemTemplate>
                                </telerik:GridTemplateColumn>  
                                                                   
                               <telerik:GridBoundColumn DataField="Family" HeaderText="Family" SortExpression="Family" Visible="false"
                                   ItemStyle-HorizontalAlign="Left" UniqueName="Family"/>
                               <telerik:GridBoundColumn DataField="Category" HeaderText="Category" SortExpression="Category" Visible="false"
                                   ItemStyle-HorizontalAlign="Left" UniqueName="Category"/>
                               <telerik:GridBoundColumn DataField="Group" HeaderText="Group" SortExpression="Group" Visible="false"
                                   ItemStyle-HorizontalAlign="Left" UniqueName="Group"/> 
                                                                                                          
                                 <telerik:GridBoundColumn DataField="StorageArea" HeaderText="Storage Area" Visible="false"
                                   UniqueName="StorageArea" ItemStyle-HorizontalAlign="Left" SortExpression="StorageArea" />
                                 <telerik:GridBoundColumn DataField="IsInventoryItem" HeaderText="Inventory Item" Visible="false"
                                   UniqueName="IsInventoryItem" ItemStyle-HorizontalAlign="Left" SortExpression="IsInventoryItem" />   
                               <telerik:GridBoundColumn DataField="AverageCostActualValue" HeaderText="Avg Cose" Visible="false" 
                                   UniqueName="AverageCostActualValue" ItemStyle-HorizontalAlign="Left" SortExpression="AverageCostActualValue" DataType="System.Decimal"/>    
                               <telerik:GridBoundColumn DataField="Parent" HeaderText="Parent" Visible="false" 
                                   UniqueName="Parent" ItemStyle-HorizontalAlign="Left" SortExpression="Parent"/>    
                               <telerik:GridBoundColumn DataField="Child1" HeaderText="Child1" Visible="false" 
                                   UniqueName="Child1" ItemStyle-HorizontalAlign="Left" SortExpression="Child1"/>    
                               <telerik:GridBoundColumn DataField="Child2" HeaderText="Child2" Visible="false" 
                                   UniqueName="Child2" ItemStyle-HorizontalAlign="Left" SortExpression="Child2"/>    
                               <telerik:GridBoundColumn DataField="Child3" HeaderText="Child3" Visible="false" 
                                   UniqueName="Child3" ItemStyle-HorizontalAlign="Left" SortExpression="Child3"/>
                                <telerik:GridBoundColumn DataField="UltimateParent" HeaderText="UltimateParent" Visible="false" 
                                   UniqueName="UltimateParent" ItemStyle-HorizontalAlign="Left" SortExpression="UltimateParent"/>                                                                      
                           </Columns>
                       </MasterTableView>
                       <SortingSettings EnableSkinSortStyles="false" />
                        <ClientSettings AllowColumnsReorder="true" ReorderColumnsOnClient="true" ColumnsReorderMethod="Reorder">                                 
                           <Resizing AllowColumnResize="True" AllowRowResize="false" ResizeGridOnColumnResize="true"
                               ClipCellContentOnResize="true" EnableRealTimeResize="false" AllowResizeToFit="true" />
                            <Scrolling AllowScroll="false" UseStaticHeaders="true" ScrollHeight="500px" />
                            <ClientEvents OnColumnClick="GridSortProcessingText" OnCommand="GridCommand"/> 
                            <ClientMessages DragToGroupOrReorder="Drag to reorder" />    
                            <Selecting AllowRowSelect="True" />      
                            <ClientEvents  />                                                                                         
                       </ClientSettings>
                   </telerik:RadGrid>
Code behind:

private void SetColumnOrderIndex(string resources)
        {
            Dictionary<string, int> dictionaryOrder = new Dictionary<string, int>();
            Dictionary<string, int> dictionaryWidth = new Dictionary<string, int>();
            Dictionary<string, bool> dictionaryVisible = new Dictionary<string, bool>();
            XDocument doc;
            if (!string.IsNullOrWhiteSpace(resources))
            {
                doc = XDocument.Parse(resources);
                foreach (XElement element in doc.Descendants("order"))
                {
                    int i = 1;
                    foreach (XElement childEllement in element.DescendantNodesAndSelf())
                    {
                        dictionaryOrder[childEllement.Attribute("columnname").Value] = Convert.ToInt16(childEllement.Attribute("columnorder").Value);
                        dictionaryWidth[childEllement.Attribute("columnname").Value] = Convert.ToInt16(childEllement.Attribute("columnwidth").Value);
                        dictionaryVisible[childEllement.Attribute("columnname").Value] = Convert.ToBoolean(childEllement.Attribute("columnvisible").Value);
                        i++;
                    }
                }
                foreach (GridColumn col in gridItemsSearch.Columns)
                {
                    foreach (string key in dictionaryOrder.Keys)
                    {
                        if (key == col.UniqueName)
                        {
                            col.OrderIndex = dictionaryOrder[key];
                            break;
                        }
                    }
                    foreach (string key in dictionaryWidth.Keys)
                    {
                        if (key == col.UniqueName)
                        {
                             if (Convert.ToInt16(dictionaryWidth[key]) > 0)
                                col.HeaderStyle.Width =  dictionaryWidth[key];
                            break;
                        }
                    }
                    foreach (string key in dictionaryVisible.Keys)
                    {
                        if (key == col.UniqueName)
                        {
                            col.Display = dictionaryVisible[key];
                            break;
                        }
                    }
                }
                gridItemsSearch.Rebind();
            } 
        }


























0
Maria Ilieva
Telerik team
answered on 01 Jul 2014, 02:19 PM
Hello Vishu,

Could you please let us know which version of the RadControls for ASP .NET AJAX you are using in your application? We had similar issue in a old version of the controls that seems to be related to the error you are facing.
Therefore I would suggest you to upgrade your application to the latest official release of the controls and verify if this helps.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Vishu
Top achievements
Rank 1
answered on 07 Jul 2014, 03:18 PM
Thanks Maria for looking into it.
             We are using Version - 2012.2.724.40 and Runtime Version- v4.0.30319.
0
Maria Ilieva
Telerik team
answered on 10 Jul 2014, 11:22 AM
Hi Vishu,

You are using rather old version of the controls. I would suggest you to upgrade to the latest official release where the described problem is fixed and verify how it goes.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Vishu
Top achievements
Rank 1
answered on 22 Jul 2014, 08:18 PM
Upgraded to 2014 and it worked like charm. 

Thanks everyone.
0
G
Top achievements
Rank 1
answered on 11 Dec 2017, 05:20 AM
In the radgrid header context menu, while deselecting all the columns from the menu but we can not deselect the last column as it is read only. Is it possible to deselect the last column also?
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
sean
Top achievements
Rank 1
Vishu
Top achievements
Rank 1
Maria Ilieva
Telerik team
G
Top achievements
Rank 1
Share this question
or