Hi,
selecting one or more Headers in the UlttraGrid and pressing Strg-C, copies the first Header and left upper cell. The cell selection below the selected Headers is correct.
The grid should work similar as Excel. The User shoulod be able to select several culumns, by clicking on the header and copy the values incl. the header text into a excel sheet.
I use the following settings:
grid.DisplayLayout.CaptionVisible = Infragistics.Win.DefaultableBoolean.False;grid.DisplayLayout.ColScrollRegions.Add(colScrollRegion1);grid.DisplayLayout.ColScrollRegions.Add(colScrollRegion2);grid.DisplayLayout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No;grid.DisplayLayout.Override.AllowDelete = Infragistics.Win.DefaultableBoolean.False;grid.DisplayLayout.Override.AllowMultiCellOperations = ((Infragistics.Win.UltraWinGrid.AllowMultiCellOperation)((Infragistics.Win.UltraWinGrid.AllowMultiCellOperation.CopyWithHeaders | Infragistics.Win.UltraWinGrid.AllowMultiCellOperation.Paste)));grid.DisplayLayout.Override.RowSizingArea = Infragistics.Win.UltraWinGrid.RowSizingArea.RowBordersOnly;grid.DisplayLayout.Override.SelectTypeCell = Infragistics.Win.UltraWinGrid.SelectType.Extended;grid.DisplayLayout.Override.SelectTypeCol = Infragistics.Win.UltraWinGrid.SelectType.Extended;grid.DisplayLayout.Override.SelectTypeRow = Infragistics.Win.UltraWinGrid.SelectType.Extended;grid.DisplayLayout.Override.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.None;grid.DisplayLayout.Scrollbars = Infragistics.Win.UltraWinGrid.Scrollbars.Both;grid.DisplayLayout.UseFixedHeaders = true;grid.DisplayLayout.ViewStyle = Infragistics.Win.UltraWinGrid.ViewStyle.SingleBand;grid.Dock = System.Windows.Forms.DockStyle.Fill;grid.Location = new System.Drawing.Point(0, 0);grid.Name = "grid";grid.Size = new System.Drawing.Size(723, 584);grid.TabIndex = 5;grid.Text = "ultraGrid1";grid.UseOsThemes = Infragistics.Win.DefaultableBoolean.True;grid.Error += new Infragistics.Win.UltraWinGrid.ErrorEventHandler(grid_Error);grid.KeyDown += new System.Windows.Forms.KeyEventHandler(grid_KeyDown);grid.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(grid_InitializeRow);grid.Validated += new System.EventHandler(grid_Validated);grid.KeyPress += new System.Windows.Forms.KeyPressEventHandler(grid_KeyPress);grid.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(grid_InitializeLayout);grid.AfterRowRegionScroll += new Infragistics.Win.UltraWinGrid.RowScrollRegionEventHandler(grid_AfterRowRegionScroll);grid.AfterSelectChange += new Infragistics.Win.UltraWinGrid.AfterSelectChangeEventHandler(grid_AfterSelectChange);
Any Ideas how to solve this?
You might want to look at the options on the AllowMultiCellOperations property. There is an option for Copy and a separate option of CopyWithHeaders. So be sure to choose the right one.
Thanks for the quick reply. Unfortunaly this is not the issue. I will make an sample:
The Grid looks like:
H1 H2 H3D1 D2 D3D4 D5 D6
H* are the headers; D* are the data cells
If I click on Header H2, which selects the column, press <Strg><C> and past into Excel. The pasted values are these:
H1 H2 H3D1 D2 D3
This is not what I expected.
The selection (blue highlighted, except the header of course) in the grid looks OK. Like the expected result:
H2D2D5
Any other ideas?
I try to create a striped code sample.
I tested this out in a small sample, and much to my surprise, I am getting the same results. Perhaps there is some reason for this, but it doesn't make any sense to me. So I'm going to forward this post over to Infragistics Developer Support and have the, investigate this as a possible bug.
So, what's the verdict? Is this a bug? If so, what's the workaround?
After looking into this in some detail, it turns out not to be as simple as it seems.There are a great many questions and issues surrounding what to do in certain situations.
Like what happens if you have both columns and rows selected?
What if you select a column in a child band in when the grid is grouped?
And how do we handle memory usage if you select a column in a grid with a large number of rows since this would force the creation of every cell in the row.
These and other issues are why this feature was not implemented originally, and so this has been entered as a feature request and may be implemented in a future release.
Hmm,
Sorry, but that's a lame answer. Nothing is easy in programming :) Note that Excel doesn't allow copy if both a row and column are selected. As for memory issues or other technical issues, as a "user" I don't care, just make it so that whatever is selected on screen is what gets put into the clipboard (boy, it feels great to be a user and say that, hah!)
Here's my workaround that I implemented in my application:
private void ultraGrid1_AfterSelectChange(object sender, AfterSelectChangeEventArgs e) { TransformColumnSelectionToCellSelection(); }
private void TransformColumnSelectionToCellSelection() { if (ultraGrid1.Selected.Columns.Count > 0 && ultraGrid1.Selected.Cells.Count == 0) { ultraGrid1.Selected.Cells.Clear(); var columns = ultraGrid1.Selected.Columns.Cast<ColumnHeader>().Select(i => i.Column); var cells = ultraGrid1.Rows.Cast<UltraGridRow>().SelectMany(i => i.Cells.Cast<UltraGridCell>().Where(j => columns.Contains(j.Column))); ultraGrid1.Selected.Cells.AddRange(cells.ToArray()); } }
Thank you ! I use 2009.1, I guess it doesn't support the Column property. I will need to find the right property for column name.
I can only assume that the version of the UltraGrid doesn't have the same properties as the version I was using. The code is essentially using Linq to get an IEnumerable list of the column names currently selected here:
var columns = ultraGrid1.Selected.Columns.Cast<ColumnHeader>().Select(i => i.Column);
Then, it uses Linq to get a list of all the cells for every row for the selected columns.
var cells = ultraGrid1.Rows.Cast<UltraGridRow>().SelectMany(i => i.Cells.Cast<UltraGridCell>().Where(j => columns.Contains(j.Column)));
This is essentially doing the same thing as a SQL "IN" statement and it's getting all of the cells which have a column named the same as the selected columns. I'm assuming this is the line you're getting the error and I'm guessing it's coming from one of two problems:
1. A null columns list. I don't do a test to ensure that this list isn't null and perhaps you need to.
2. Inside the Where clause. I'm using WinGrid 2009.2 and an UltraGridCell has a Column property with the name of the column in it. Does your UltraGridCell have the Column property in it?
Good luck!
robarch, I used your code but got error message "cannot resolve symbol 'Column' " when getting the value of columns. Do you have any idea why ?
Hi David,
The word is that this is currently working as designed and this is considered a feature request. So it may be added in a future release. :)
robarch - your solution works great for me too!
Mike - any word on a bugfix for this?
Thanks to both of you!
David McClelland