I have tried to follow the example in the documentation for XamGrid Export to Excel at http://help.infragistics.com/Help/NetAdvantage/Silverlight/2011.1/CLR4.0/html/SL_Exporting_xamGrid_Data_to_Excel.html, and it does not work in my case. Some of my columns are GroupColumns. For example, the "Security Id" and "Security Name" columns are inside a "Security" GroupColumn. When I implement the Export to Excel logic in codebehind, and loop through the cells of each row, only the GroupCell appears in the collection of cells, and the Value property of this is null.
There are no obvious properties of this object that would allow me to pull the value of the child columns (e.g. Security Id).
How do I implement Export to Excel if my grid uses GroupColumns?
When you are looping through the cells are you using the columns of the column layout to provide you with the keys to find the cell?
If you are then you need to look inside the GroupColumn to find the columns that are under it. The Grid already has a mechanism for this, the .AllColumns collection off the Columns collection
columnLayout.Columns.AllColumns
This gives you a recursive list of all columns under the column layout. As you cycle your columns just omit the GroupColumn.
foreach (Column c in columnLayout.Columns.AllColumns)
if ( c is GroupColumn)
continue;
// otherwise export
Darrell,
Thanks for your reply. I am not using the colunms of the column layout, because this does not help me find the value of the cells when there are groupcolumns.
For example, assume my grid looks like this:
---------------------------------------
| Security | <-- 'Security' is the key of the Group Column
| Security Id | Security Name | <-- 'SecurityId' and "SecurityName' are keys
| MSFT | Microsoft | | GOOG | Google |
When I loop through the columns as you suggested, there is no way to retrieve the cell values for either of the two rows. The grid.Rows[0].Cells collection contains 1 item, which is of "GroupCell" type, with key 'Security", and has a null value. Attempting to retrieve grid.Rows[0].Cells['SecurityId'] will result in an Exception.
Please advise.
I ran into this problem too. My grid has a context menu on it with a "Copy Cell Value" action and while getting that action to work on a grid without group columns was simple enough, I have yet to be able to figure it out for group columns because I can't find the value for the selected cell at least in the 10 minutes or so I looked at it in the debugger. Hopefully Darrell or someone will get back to us.
FWIW, I was able to figure it out with the comment Darrel made - here is my code:
if (action == "Copy Cell")
{
foreach (var gcell in ONTsGrid.SelectionSettings.SelectedRows[0].Cells)
if (gcell is GroupCell)
foreach (var col in gcell.Column.AllColumns)
var cell = ONTsGrid.SelectionSettings.SelectedRows[0].Cells[col];
if (cell.IsActive == true)
Clipboard.SetText(cell.Value.ToString());
}
Thanks - this clarification helped as it was not obvious. This works for me now.
Thanks, it is working.
But there is one bug(?): when you hide GroupColumn, its children column don't change property Visibility to Visibility.Collapsed
Hi,
Darrell's approach is actually correct, however there is one additional step.
You can retrieve any cell by passing in a column:
Cell cell = grid.Rows[0].Cells[(Column)grid1.Columns.AllColumns["ColKey"]]
Hope this helps,
-SteveZ