HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress
Showing posts with label WWW. Show all posts
Showing posts with label WWW. Show all posts

Saturday, July 14, 2012

WinForms Grid - Add a New Item to the Grid's Popup Menu

In this video, you will learn how to add items to the popup menu that appears when right-clicking on the grid’s footer. We will use the gridView’s “ShowGridMenu” event to add a DevExpress MenuItem to the context menu.
1.       I’ll start with a WinForms application that has a Grid Control bound to the Orders Table of the NorthWind Sample Database.
2.       First, I need to enable the footer in order to be able to access its context menu at runtime.
3.       To do this, I run the Grid’s Designer and switch to the Feature Browser.
4.       I expand “Summary”, “Total Summary” and select “Footer”.
5.       On the right, I click on the “OptionsView.ShowFooter” link to make the grid’s footer visible.
6.       And I’m done.
7.       I close the designer and return to Visual Studio.
8.       I select the gridView and create a new handler for its “ShowGridMenu” event.
9.       This event is fired when the user right-clicks on the grid’s footer.
10.   Before adding any code to the event handler, I’m going to create a custom event handler that will be triggered when the new MenuItem is clicked.
private void MyMenuItem(object sender, System.EventArgs e) {
DevExpress.Utils.Menu.DXMenuItem Item =
                (DevExpress.Utils.Menu.DXMenuItem)sender;
      DevExpress.XtraGrid.Menu.GridViewFooterMenu menu =
                (DevExpress.XtraGrid.Menu.GridViewFooterMenu)Item.Tag;
      MessageBox.Show(menu.View.FocusedColumn.Caption);
}

11.   This will create a new messagebox, displaying the name of the selected column.
12.   Now, I’m going to add the following code to the event handler.
13.   This will add a new entry, “MyItem” in our case, and associate it with the “MyMenuItem” method I created earlier.
if(e.MenuType != DevExpress.XtraGrid.Views.Grid.GridMenuType.Summary)
     return;
DevExpress.XtraGrid.Menu.GridViewFooterMenu footerMenu =
          (DevExpress.XtraGrid.Menu.GridViewFooterMenu)e.Menu;
DevExpress.Utils.Menu.DXMenuItem menuItem = new
           DevExpress.Utils.Menu.DXMenuItem("MyItem",
           new EventHandler(MyMenuItem));
menuItem.Tag = e.Menu;
footerMenu.Items.Add(menuItem);

14.   And that’s it!
15.   I run the application to see the results.
16.   I right-click on the footer of the grid and the context menu now includes the new item.
17.   I click on it and the “MyMenuItem” event handler is invoked a creating a messagebox with the name of the currently selected column.
Thanks for watching and thank you for choosing DevExpress!

Enhanced by Zemanta

XtraGrid - Introducing the Feature Browser

In this lesson, I’ll demonstrate how to use the Feature browser tool, which helps you easily customize the XtraGrid Control.
The Feature Browser provides a structured feature list with related settings. I’m going to demonstrate how to access and customize settings that relate to the view’s preview and filter features.
1.       I invoke the Feature Browser, and select Preview to access the settings that relate to the view’s preview feature.
2.       Selecting the Preview feature, results in the Property Grid being filtered, so that only the properties and events that relate to this feature are displayed.
3.       So, let’s enable the “Show Preview” option, to display row preview sections.
4.       Now, I need to specify the name of the field, whose values are displayed within preview sections.
5.       Let’s use the Phone field.
6.       Then, I access the settings that relate to the view’s filter feature, and enable the “Show Auto Filter Row” option, to allow data to be filtered by typing text within the row.
7.       And I’m done!
8.       I close the designer, and run the application.
9.       The row preview sections now display the customer’s phone number.
10.   The “Auto Filter” row, is displayed at the top of the view.
11.   I type text within the row, and a filter condition is automatically created based upon the value entered, and this is applied to the focused column.

Enhanced by Zemanta