Hi,
Is it possible to draw rectangle(s) on a continuous rows in UltraGrid control? Is there any sample or KB that could help me with this? I've been looking for samples on how to use DrawFilter but I'm not sure it can be used to solve the problem. Thanks.
It sounds like this should be fairly easy to do using a DrawFilter. But I'm not sure exactly what you mean by:
2cool said:draw rectangle(s) on a continuous rows
Can you explain what you mean in a little more detail exactly what you want to draw rectangles around?
Thanks Mike for your respond. The image below is a sample result I'm looking for. I'm trying to create grouping feature that a rectangle will be drawn on rows that are selected continuosly, for example rows index 2,3,4. In the image below, there are 3 groups presented using different color of rectangles. The second rectangle (red) has another grouping (green) in it and I need to make sure that when drawing the red rectangle, it won't overlap the green one. Many thanks.
This definately seems like something you could do with a DrawFilter. If you have not had any experience with DrawFilters, then I recommend that you check out the Infragistics Knowledge Base. There are lots of articles with sample DrawFilters. None of them do exactly what you want here, but it's a good starting point.
Also, get the Infragistics UIElementViewer Utility. It's a huge help when working with UIElements.
The basic approach I would take here is to find out what the UIElement is that contains the RowUIElements. I think it's probably something like the RowColRegionIntersectionUIElement, but I could be wrong and the UIElementViewer utility will help you find the right one.
Then I would use a DrawFilter to handle the AfterDrawElement for the container element. You could loop through the child Elements of it and find RowUIElements and use those to determine the visible rows and their rects and then draw your rectangles wherever you like.
Let me know if you have any questions or get stuck and I will try to point you in the right direction.
Thanks Mike. I think what you described on how to use DrawFilter is pretty close to a sample that I found in KB: How can I change the border color of a single cell or row in the grid? Using sample code in KB, I tried to draw two borders on activerow, but I couldn't get the second rectangle drawn on top of the first one. Could you tell what I'm missing? Many thanks.
Hi Mike. I just figured out how to draw more than one rectangles on a multiple rows using sample code from KB using UIElementDrawParams.Graphics.DrawRectangle. But there's a few other issue I hope you could guide me,
1. Is it possible to set RowSpacingBefore and RowSpacingAfter selectively. For example if I draw a rectangle for row index 2 and 3, and then another rectangle on row index 2 to 4, then I'll have two rectangles that are not overlapping each other from row index 2 to 4. I need adjust RowSpacingBefore and RowSpacingAfter so that the outer rectangle won't cover the row on top of it. But adjusting RowSpacingBefore and RowSpacingAfter apply to all rows in the grid. Can I adjust for example the distance between row 1 and 2 only?
2. How do I get a rectangle, for example, of selected row? Assuming that selected row are continuos, e.g: row index 2,3, and 4. Currenty I'm calculating the rectangle of each rows then draw the rectangle. I wonder if there's an easy way to do this without having to keep track on the changes (that if it's possible with question1).
3. How do I set the distance of grid control to data area (I'm not sure if I'm using the right term here)? If you see the image I posted, I got more space on left side of RowSelector and also the right side to show the rectangles. Below is my test application screenshot.
4. This one is probably not a smart question but how do I get the rectangles drawn to stay? Basically, the feature that I need to implement is like this, when user make a selection of rows then hit a "Group" button, I need to draw a rectangle. If user make another selection, I need to draw another rectangle, and so on. Could this be done without storing/using data bounded in datagrid for conditional drawing?
Thanks so much.
Eric said:1. Is it possible to set RowSpacingBefore and RowSpacingAfter selectively. For example if I draw a rectangle for row index 2 and 3, and then another rectangle on row index 2 to 4, then I'll have two rectangles that are not overlapping each other from row index 2 to 4. I need adjust RowSpacingBefore and RowSpacingAfter so that the outer rectangle won't cover the row on top of it. But adjusting RowSpacingBefore and RowSpacingAfter apply to all rows in the grid. Can I adjust for example the distance between row 1 and 2 only?
There are RowSpacingBefore and RowSpacingAfter properties on the individual rows. So you could set this in the InitializeRow event to create space for the DrawFilter to draw in.
Eric said:2. How do I get a rectangle, for example, of selected row? Assuming that selected row are continuos, e.g: row index 2,3, and 4. Currenty I'm calculating the rectangle of each rows then draw the rectangle. I wonder if there's an easy way to do this without having to keep track on the changes (that if it's possible with question1).
I assume you are doing this inside the DrawFilter. So what you would do is loop through the ChildElements of whatever element contains the RowUIElements. For each RowUIElement you can call GetContext to get the UltraGridRow so you can check if it's selected. Then you could use the Rect property on the RowUIElement to get the rect of the row.
Eric said:3. How do I set the distance of grid control to data area (I'm not sure if I'm using the right term here)? If you see the image I posted, I got more space on left side of RowSelector and also the right side to show the rectangles. Below is my test application screenshot.
Hm. This is a tricky one. You can get space on the left by using the Indentation property on the Band, I think. I don't think there is any way to get extra space on the right, though.
Eric said:4. This one is probably not a smart question but how do I get the rectangles drawn to stay? Basically, the feature that I need to implement is like this, when user make a selection of rows then hit a "Group" button, I need to draw a rectangle. If user make another selection, I need to draw another rectangle, and so on. Could this be done without storing/using data bounded in datagrid for conditional drawing?
The DrawFilter gets called every time the grid paints. So you need to write your DrawFilter in such a way that it always draws whatever lines are needed based on the current state of things. You don't really make the lines "stay". You constantly re-draw them every time the grid paints.