I have added a record count label to the grid with a creation filter. I am showing the record count in the caption area of the grid and want to show it on the far right side. However, as the record count changes, I would like to change the width of the UIElement accordingly. I have other button in the same area and I would like them all to be aligned against the right side of the grid control. I would like the record count to be the right-most UIElement. Does anybody know how I can get this item to autosize? I also need to adjust the position of all the other buttons whenever the record count button's size changes.
I'm not sure what you are asking. Which part of this are you having trouble with?
There's no way to autosize the element to it's context, you will need to measure the text. I beleive there are methods on the Infragistics.Win.DrawUtility which you can use in your CreationFilter to do this and then determine the rect of your element.
In order to get the element to resize when the value changes, what you will need to do is get the CreationFilter to re-fire and re-crete the elements. One way to do this would be to call DirtyChildElements on the grid.DisplayLayout.UIElement. This dirties the UIElement hierarchy so that the grid will re-position the elements the next time it paints.
Mike:
I am creating a custom UIElement to show the number of rows in the grid. As the number of rows changes, I need to adjust the width of the UIElement for wider/narrower text. I am using the OnBeforeDraw event of the UIElement. Can you tell me what VB.Net code I should use to measure the text in that event and how to adjust with width of the UIElement?
Rich
Hi Rich,
I would not attempt to resize an element in OnBeforeDraw. I'm not even sure what you mean - OnBeforeDraw of what - the element itself? I think changing the size of an element inside it's own draw method might cause the draw method to fire recursively.
I would size the element at the time you create it, inside the CreationFilter.
I don't have any sample code for this, but I think the easiest way to measure a string is to use Infragistics.Win.DrawUtilty.MeasureString.
I've got code in the CreationFilter and I am able to size the object fine the first time. Let's say the grid has 1 row in it when it is painted and the width turns out to be 80. Now, I load the grid up with 10,000 rows and the element needs to be a little bit wider to hold the extra characters. What would be the best event to change the size of the element? I was thinking the OnBeforeDraw of the element because there is no OnPaint event exposed for the element.
Hi Richard,
I would still do it in the CreationFilter. The CreationFilter should create this new element, set it's text and determine it's size all in one place. When you add a row to the grid, I'm pretty sure the CreationFilter will fire again and re-create the element. If I am wrong, then all you have to do to make it happen is call grid.DisplayLayout.UIElement.DirtyChildElements and the creation filter will get called the next time the grid paints.
You might want to make this more efficent by caching the element, it's size, andit's text and re-use the same element if nothing has changed. But it's not strictly neccessary - especially if it's just one element.
Mike, you are THE MAN! You gave me exactly what I needed to make this work. The elements are indeed recreated when the grid paints so I was able to do away with a bunch of extra code.