Can someone please help me with this. I found on the site how to select the entire range of the grid but it didn't explain the copy part which I am equally ignorant in.
I want to simply press a button and have the contents of the grid on the clipboard, ready to be dropped in excel. If possible I would like the logic to allow for the user to be able to group a number of different columns and only copy to the clipboard what is being displayed on the screen.
Thanks for the help.
Hi,
Once you have selected the rows you want, copying to the clipboard is pretty simple. Make sure you have the grid set up to allow copying.
So make sure you have AllowMultiCellOperations (on the Override) set to allow copying. And then you can perform a copy operation in code like so:
this.ultraGrid1.PerformAction(UltraGridAction.Copy, false, false);
I'm not sure what you mean about grouping and the visible rows. Do you mean you only want to copy rows that are in the visible area of the grid? You want to exclude rows that are selected, but are scrolled out of view? I don't think there is any way to do that. But you could select only the rows that are in view using the grid.ActiveRowScrollRegion.VisibleRows collection.
After further search in the forums I came across this ...
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=6546
which showed me that the following is all you need...
grid.Selected.Rows.AddRange(grid.Rows.GetAllNonGroupByRows())
Thanks!
If it is grouped I want to select from the group. If there is no grouping I want to select all of them. Unless you have a better suggestion. Just trying to achieve how most users would expect the application to operate.
I am currently using 2006 vol 1 CLR 2.0. My company's most recent version is 2010 Vol 2 but I inherited a project using the 2006 version and have yet to install the newest one.
I apologize for my lack of clarity.
I want to select all data rows within a single group IF a grouping exists. If a grouping does not exist, select all data rows in the grid.
Okay, that's pretty easy. But how do you want to determine which group to select?
You already know how to select all of the rows when there is no grouping - you just use the grid's Rows collection.
If you have groups, then you can do the same thing, you just have to use a different rows collection - you need a collection of DataRows under the GroupByRow.
There is still a lot of ambiguity in your question, thought. If you have multiple levels of grouping, this gets a little trickier, because you could select the immediate children of the GroupByRow (which could also be GroupByRows) or you might want to walk all the way down the chain until you get to a set of Data rows.But since the child data rows will be broken up into multiple groups, I don't know what you would want to do in that case. You could just select the first set of child data rows, I guess.
Anyway, in a simple case like your screen shot here where you have only a single level of grouping and there is a GroupByRow selected and active, you could select the child rows of that GroupByRow by casting the grid's ActiveRow into an UltraGridGroupByRow and using it's Rows collection.
(grid.Selected.Rows.AddRange(groupByRow.Rows)
But if I'm wanting to put this logic within the same button, how do I know whether the ultragrid is grouped or not?
This goes back to the question of which group you want to copy.
You can detect the precense of grouping in the grid by examining the band.SortedColumns collection. You would loop through the collection and look for a column whose IsGroupByColumn property is true. If any are true, then there is grouping applied to that band.
If you have a particular row as a starting point, like the grid's ActiveRow, then you could look at the IsGroupByRow property of the row, or any of it's parent rows up the chain.