0

I want to display a limited number of columns in a grid that is connected to a DataTable as the data source. In an example that I found, it uses the property, ExtendedProperties to define how the column headers are displayed, the order and which columns are selected. However, when I use this, the columns, order and number displayed are the same as in the original DataTable.

Can anybody see what I am doing wrong?

This is a subset of the code. It is just the Customer's Table:

// initialize db connection variables
        string conn = GetConnectionString();

        // load some tables
        string[] tables = "Customers, Orders, Order Details, Products, Employees, Shippers".Split(',');
        foreach (string tableName in tables)
        {
            FillTable(_ds, tableName, conn);
        }
dt = _ds.Tables["Customers"];
// re-arrange the columns on the customer table
        //
        dt.ExtendedProperties.Add("ShowColumns", new string[] {
                                                                  "CustomerID, Customer",
                                                                  "OrderCount, Orders",
                                                                  "CompanyName, Company",
                                                                  "ContactName, Contact",
                                                                  "Phone",
                                                                  "City",
                                                                  "Region",
                                                                  "Country",
        });

        // show customers to begin with
        _flex.SetDataBinding(_ds, "Customers");

The method that sets up the columns:

    // customize grid display to show selected columns, captions, formats, and data maps
    void _flex_SetupColumns(object sender, System.EventArgs e)
    {
        // get grid that was just bound
        C1FlexDataTree grid = sender as C1FlexDataTree;
        if (grid == null || grid.DataSource == null)
            return;

        // get source DataTable
        CurrencyManager cm = (CurrencyManager)BindingContext[grid.DataSource, grid.DataMember];
        DataTable dt = ((DataView)cm.List).Table;

        // apply custom column order, captions, format
        string[] columns = dt.ExtendedProperties["ShowColumns"] as string[];
        if (columns != null)
        {
            SetupColumns(grid, columns);
        }

        // apply custom data maps
        foreach (Column gridColumn in grid.Cols)
        {
            DataColumn dataColumn = dt.Columns[gridColumn.Name];
            if (dataColumn == null) continue;
            gridColumn.DataMap = dataColumn.ExtendedProperties["DataMap"] as IDictionary;
            if (gridColumn.DataMap != null)
            {
                gridColumn.TextAlign = TextAlignEnum.LeftCenter;
            }
        }

        // all done, autosize to show mapped data
        if (grid.AutoResize)
        {
            grid.AutoSizeCols(12);
        }
    }

The method, 'SetupColumns' is never called.

Gloria Santin
  • 2,066
  • 3
  • 51
  • 124

1 Answers1

0

I figured this out. My problem was that I had not defined the Event within the grid so it was not firing. Once I did that, it worked fine.

Gloria Santin
  • 2,066
  • 3
  • 51
  • 124