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

Column Headers not being exported to Excel when More then 10 Rows are exported

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 2
Tim asked on 21 Feb 2012, 09:39 PM
2 problems here;
1. Header row (column titles) are not exported to Excel when I have more than 10 items in a export. I thought it might be related to the page size so I changed my page size to encompass 12 rows and still no header row.
2. I am unable to get the entire dataset to export to excel. I can only get the 1st page. See code snipit

ActiveBatchesRadGrid_ItemCommand calls the method ConfigureExport in the base class so all exports function the same

private void ActiveBatchesRadGrid_ItemCommand(object source, GridCommandEventArgs e)
{
    switch (e.CommandName)
    {
        case RadGrid.InitInsertCommandName:
            _gridTableView = e.Item.OwnerTableView;
            break;
        case RadGrid.ExportToExcelCommandName:
            ExpandAllDetailTableRecords(source, ExpandedStates, false);
            ConfigureExport(source, e);
            break;
    }
 
 }



protected static void ConfigureExport(object source, GridCommandEventArgs e)
{
    e.Item.OwnerTableView.ExpandCollapseColumn.Visible = false;
    e.Item.OwnerTableView.GetColumn("PolicyEditRecord").Visible = false;
    e.Item.OwnerTableView.GetColumn("DeleteTransaction").Visible = false;
    e.Item.OwnerTableView.GetColumn("ManualAdjustmentBatchID").Visible = false;
    e.Item.OwnerTableView.GetColumn("ManualAdjustmentID").Visible = false;
    ((RadGrid)source).ExportSettings.ExportOnlyData = true;
    //((RadGrid)source).PageSize = ((RadGrid)source).MasterTableView.VirtualItemCount;
    ((RadGrid)source).ExportSettings.IgnorePaging = true;
    ((RadGrid)source).ExportSettings.OpenInNewWindow = false;
    ((RadGrid)source).MasterTableView.HierarchyDefaultExpanded = false;
    ((RadGrid)source).MasterTableView.ExportToExcel();
 
}

VirtualItemCount is commented out because it throws an "System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values." error. I have not tried it yet but I think it may be due to the export being conducted on the DetailGrid and not the MasterGrid. Any comments on that would be appreciated too.


EDIT:
After further investigation the lack of the export of the header row does not appear to be a row count issue. It appears that only the first DetailGrid of the first row of the MasterDetailGrid exports the column headers. I have tried this on all of my implementations and the behavior is consistent across them

1 Answer, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 2
answered on 22 Feb 2012, 08:21 PM
Ok, I think I solved issue number 1.
I am using a modified RadGrid State Management as described in this article my ExpandAllDetailTableRecords is in the base class so all grids can call the same process.

I was passing false to expanded instead of using the (bool)expandedStates[key] to set my Item expanded state. so the for {} statement was always closing the header row. The intent for this process was to make sure that all DetailGrids that are children of the rows of this DetailGrid are closed prior to export.

Uncorrected Code:
protected static void ExpandAllDetailTableRecords(object source, Hashtable expandedStates, bool expanded)
{
    string[] indexes = new string[expandedStates.Keys.Count];
    expandedStates.Keys.CopyTo(indexes, 0);
    ArrayList arr = new ArrayList(indexes);
    arr.Sort();
     
    foreach (string key in from string key in arr let value = (bool)expandedStates[key] where value select key)
    {
        ((RadGrid)source).Items[key].Expanded = expanded;
    }
}

Corrected Code:
protected static void CloseAllDetailTableRecords(object source, Hashtable expandedStates)
{
    string[] indexes = new string[expandedStates.Keys.Count];
    expandedStates.Keys.CopyTo(indexes, 0);
    ArrayList arr = new ArrayList(indexes);
    arr.Sort();
 
    foreach (string key in arr.Cast<string>().Where(key => key.Contains(":")))
    {
        ((RadGrid)source).Items[key].Expanded = false;
    }
}




Tags
Grid
Asked by
Tim
Top achievements
Rank 2
Answers by
Tim
Top achievements
Rank 2
Share this question
or