Blogs

Paul Kimmel's Blog

January 2010 - Posts

  • Disable Sorting in OLAP Mode for PivotGrid New in v2009 Volume 3

         

    By default the XtraPivotGrid (PivotGridControl) sorts field values (row and column headers) in ascending or descending order. OLAP cubes can define their own ordering. If you want to maintain the cube’s ordering then you can disable field ordering. When working with an OLAP cube if you set a pivot grid field’s SortMode to None then default ordering is turned off. New in v2009 volume 3 is the Clear Sorting feature. Clear Sorting, as well as the A-Z and Z-A, ordering let you re-order the data or clear ordering altogether.

    When you turn automatic sorting off by setting a field’s SortMode to None the PivotGridControl’s header context menus will show these additional header context menu items (see Figure 1). The following steps walk you through constructing the sample solution.

    image
    Figure 1: The new Clear Sorting context menu item shows up when automatic filtering is turned off for a field by setting SortMode to None.

    Constructing the XtraPivotGrid (PivotGridControl) Demo

    I am using the XtraPivotGrid version 2009 volume 3 for the demo. The data comes from the Northwind database and a .cub file was created using Microsoft Excel’s export cube feature. (DevExpress’ book Professional DevExpress ASP.NET Controls chapter 8 talks about how to export a cube file.) To create the demo follow these steps:

    1. Create WinForms project

    2. Add a PivotGridControl to the form and dock it

    3. Place the cube file in your project, somewhere that it is accessible

    4. Define a connection string using the Smart tags’ Choose OLAP Data Source wizard, or simply define the connection string in the PivotGridControl’s OLAPConnectionString property, similar to the following:

    Provider=msolap;Initial Catalog=Northwind;Cube Name=Northwind;Data Source=c:\devexpress\winforms\olapdemo\OlapDemoWinForms\Northwind.cub

    (If you define an OLAPConnectionString then the DataSource property is cleared and vice versa.)

    5. Right click on the PivotGridControl (or the Smart tags menu) and click on Run Designer to run the field’s designer (see Figure 2)

    6. Add six fields in the designer using the Add button. (The fields for the demo are City, Category name, Products, Country, Quantity, and Discount)

    7. You will need to set the field properties based on where you want the data to appear in the pivot grid. To create the result shown in Figure 3 use these settings:

    City – Caption is City, Area is FilterArea, FieldName is [Customers].[City].[City], and SortMode is None

    Category Name – Caption is Category Name, Area is RowArea, FieldName is [Categories].[Category Name].[Category Name], and SortMode is None

    Products – Caption is Products, Area is RowArea, FieldName is [Products].[Products].[Products], and SortMode is None

    Country – Caption is Country, Area is ColumnArea, FieldName is [Customers].[Country].[Country], and SortMode is None

    Quantity – Caption is Quantity, Area is DataArea, FieldName is [Measures].[Quantity], and SortMode is None

    Discount – Caption is Discount, Area is DataArea, FieldName is [Measures].[Quantity], and SortMode is None

    8. Close the designer. (The design-time view is shown in Figure 3.)

    9. Run the demo. The results at runtime (Figure 4) with the Clear Sorting context menu item is shown in Figure 1.

    The XtraPivotGrid is a great tool for exploring and arranging your data to figure out what it all means, collectively referred to as data mining.

    The Clear Sorting feature is also supported for the ASP.NET ASPxPivotGrid (and you can use the same .cub file, if you don’t have Microsoft Analysis Services handy.) If you are having trouble getting your hands on a cube file or following Excel’s instructions for creating one drop me a line and I will email you the one for the demo.

     

    image
    Figure 2: Add the fields using the designer (shown above).

    image
    Figure 3:  The design-time results based on the designer settings.

     

    image
    Figure 4: The PivotGridControl at runtime with the configured data.

  • Handling focus Row Change in XtraGrid

         

    A customer asked me yesterday: “I am frustrated. I looked in the Properties window event tab for the XtraGrid.GridControl and cannot find event that tells me when the focused row has changed?” I said I appreciate your frustration; let me help. So, as not to give him a doh! moment with the easy answer, i used the sample code he sent me, completed it and sent it back with a “its the FocusedRowChanged event, which you can find in the events view of the designer”.

    Like the guy that showed me how to change a fan belt—not by removing the radiator and fan as I tried to do at 15—but by loosening the alternator, its all about knowing the answer. From the designer implement the FocusedRowChanged event, grab the FocusedRowHandle from the event argument DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e and ask the grid for the row, passing in the FocusedRowHandle. Listing 1 demonstrates the solution.

    There are support center posts about this kind of problem, which you can find by Googling for them, or by going directly to our support center or forums at http://community.devexpress.com/forums/. Of course, if you are frustrated it is always nice to reach out to support—they can often find existing posts quickly—or ping one of the evangelists. (The last choice gives us a reason to sling a little code every day.)

    Listing 1: Determining what the focused row is in FocsuedRowChanged event.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace FocusedRowDemo
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();

          BindingList<guiListItem> list = new BindingList<guiListItem>();

          for (int i = 0; i < 100; i++)
          {
            guiListItem item = new guiListItem(i, "Description " + i.ToString(), "item" + i.ToString());
            list.Add(item);
          }
          gridControl1.DataSource = list;
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
          //here
          guiListItem item = (guiListItem)gridControl1.DefaultView.GetRow(e.FocusedRowHandle);
          MessageBox.Show(item.Description);
        }
      }

      public class guiListItem
      {
        /// <summary>
        /// Initializes a new instance of the guiListItem structure.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="description"></param>
        /// <param name="value"></param>
        public guiListItem(int key, string description, string value)
        {
          Key = key;
          Description = description;
          Value = value;
        }
        public int Key{get; set;}
        public string Description{get; set;}
        public string Value{get; set;}
      }
    }

  • Automatic Edit Type Switching New in v2009 Volume 3

         

    Some features are small and to the point. New features are being added all the time. The feature in this blog is short and to the point and it is a design time feature, so I combined it with another feature.

    Suppose you have a TextEdit control on a form and you set the TextEdit.Properties.Mask to ‘f’ for Full date/time (short time) using the Mask Editor (see Figure 1). You now also have the design time capability—a new feature in volume 3—of changing the actual design control while keeping layout and location the same. For example, to change the TextEdit control to a DateEdit control at design time click the TextEdit’s smart tags menu, click Change editor type (see Figure 2). All control types can be changed this way and you get to avoid the headache of reconstructing your very carefully constructed layout.

    image
    Figure 1: The Mask Editor let’s you pick from pre-defined edit masks for the TextEdit control.

     

    image
    Figure 2: Change control types in place on the fly at design time.

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.