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

Modifying FilterMenu item texts programatically

2 Answers 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DrKawashima
Top achievements
Rank 1
DrKawashima asked on 26 Jul 2012, 08:55 AM
Hi,
I need to modify the item texts of a radgrid's FilterMenu ( for example changing "Order by", "Contains" and "Does not contain" to something else)

My attempted solution is to add a RadMenuEventHandler  to the FilterMenu.ItemCreated event, so that when a filtermenu item is created, my method FilterMenu_ItemCreated will fire and replace the necessary texts.

However the FilterMenu_ItemCreated  method never fires. And I'm not sure why

 I've have previously been successful when using the same approach for modifying texts inthe HeaderContextMenu. I just added an event handler for the ItemCreatedEvent (like this: grid.HeaderContextMenu.ItemCreated += new RadMenuEventHandler(HeaderContextMenu_ItemCreated); ) and that worked perfectly fine. 

So I'm confused why the same approach doesn't work for the FilterMenu

Below is some code:
----------------------


This is basically how the grid is set up. The event handler is added on the last line
RadGrid grid = new RadGrid();      
grid.ID = "radgrid1";   
....
grid.MasterTableView.AllowFilteringByColumn = true;
grid.MasterTableView.EnableHeaderContextFilterMenu = true;
grid.HeaderContextMenu.ItemCreated += new RadMenuEventHandler(HeaderContextMenu_ItemCreated);
grid.FilterMenu.ItemCreated += new RadMenuEventHandler(FilterMenu_ItemCreated);

A simplified version of the method which should fire during the ItemCreated event.


void FilterMenu_ItemCreated(object sender, RadMenuEventArgs e)
        {
  
            string newHeader = RadGridHelper.GetLocalizedTextForFilterMenuItems(e.Item.Text);
            if (!String.IsNullOrEmpty(newHeader))
                e.Item.Text = newHeader;
    #if DEBUG
            LogUtil.Log(String.Format("GetLocalizedTextForFilterMenuItems {0}", e.Item.Text));
#endif
        }
 
public static string GetLocalizedTextForFilterMenuItems(string text)
        {
 
            switch (text)
            {
                case "Between": return "Mellan" ;
    }}

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Jul 2012, 09:34 AM
Hi,

I suppose you want to localize the RadGrid FilterFunction text. Following is the sample code.

C#:
protected void Page_Load(object sender, EventArgs e)
{
    GridFilterMenu menu = RadGrid1.FilterMenu;
    foreach (RadMenuItem item in menu.Items)
    {    //change the text for the "StartsWith" menu item 
        if (item.Text == "StartsWith")
        {
            item.Text = "your_custom_localized_string";
        }
    }
}

Thanks,
Shinu.
0
DrKawashima
Top achievements
Rank 1
answered on 26 Jul 2012, 12:01 PM
Thanks, Princy. That solved it. :)
Tags
Grid
Asked by
DrKawashima
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
DrKawashima
Top achievements
Rank 1
Share this question
or