I have a WinGrid with several columns. Each column has a header and the grid has several rows. When a user clicks on the column header I have code the changes the background color to indicate the column was selected. I also have a right click popup menu defined.
When a user right clicks on the column header, I want to copy the entire column, header and data, so the data can paste into Excel. But this isn't working. I can see the column in the Selected.Columns collection, but nothing on the clipboard.
Any suggestions or exmaple links? Thanks.
Hi Thom,
When using UltraGridAction.Copy it actually copies the grid's selected cells. You might have already noticed that the UltraGridColumn class does not contain a Cells collection. This is why you don't get a copy by column. If you take a closer look you'll notice that the Selected.Columns actually contains mainly headers. You can use them to loop trought the cells and check which ones you have selected. I have created some code for you doing this:
foreach (UltraGridRow row in ultraGrid1.Rows)
{
foreach (UltraGridCell cel in row.Cells)
if (ultraGrid1.Selected.Columns.Contains(cel.Column.Header))
ultraGrid1.Selected.Cells.Add(cel);
}
ultraGrid1.PerformAction(UltraGridAction.Copy, false, false);
This is what you might use in yout "CopiClick" event...
And in order to have not only cells but also the ColumnHeaders there is a property you can set to add them to the data you are copying whether it is row or cell-typed:
ultraGrid1.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.CopyWithHeaders;
Hope this is what you needed.
Sincerely,
Petar Monov
Developer Support Engineer,
Infragistics, Inc
Right, so I have a grid with header and cell data. When a user clicks on the header and chooses my Copy option from a popup menu, the all the data from the header down, all cells, are copied to the clipboard, so that I can then go to excel and paste the data into a spreadsheet.
Works fine on cell and row data with the PerformAction method, but not on Columns (even though I show columns selected in the MyGrid.Selected.Columns property.
Just to make things clear. You want to do Copy/Paste from ultraGrid to Excel right?
Thank you for replying. However, I need to copy the data from a selected column when right clicking on the Header of the column, to the Windows clipboard so I can then paste it into Excel. Any suggestions there?
Hello,
There is a suitable event in the grid - DoubleClickHEader and you'll need a variable of type UltraGridColumn to store the copied column:
private void ultrGrid1_DoubleClickHeader(object sender, DoubleClickHeaderEventArgs e)
UltraGridColumn copiedColumn = e.Header.Column;
Hope this helps.