Hello,
I have a UltraGrid and I need to set one cell of it.
I need to create a cell that has two RadioButtons on the same cell. Is that possible?
Thank you,
Best regards,
Maria
Hi Maria,
Yes... add an UltraOptionSet control to the form with the grid. Set the grid cell's EditorComponent property to the UltraOptionSet.
Thank you for your answer.
I've read about UltraOptionSet but I didn't understand how to use it. Can you give me an example?
There's no way to center the options. That seems like a very odd thing to do. Why would you want to, though? Typically, when using radio buttons, you always want the circles to line up in a nice neat stack. Unless the text of every option was exactly the same, centering the radio buttons would cause the buttons themselves to be out of alignment with each other.
You can shift the items using the ItemOrigin property, but there is no property that will center them.
If you really want them centered, then you could probably achieve that using a CreationFilter, but it could be tricky if you have no used CreationFilters before. And as I said, it's a very strange UI. I have never see an application with centered radio buttons before.
Hi Mike. I'm not the original creator of this thread but I have a similar problem. I have attached an image of my grid. As you can see, the two radio buttons (UltraOptionSet) are not centered within the cell but are at the top-left of the cell. Is there an easy way to center the UltraOptionSet as a whole within the cell? Will a CreationFilter achieve this? Note that I don't want each radio button centered independently, but both of them as a unit, which is why the text of each option can be different lengths.
Thanks!
Hi,
There's no property for this. If the column width is fixed, then you could probably handle this using the ItemOrigin property on the UltraOptionSet control. You would have to figure out the proper origin to make the items centered, though. I don't know if there is a good way to calculate it, you would probably have to rely on trial and error.
The most reliable and flexible way to handle it would be a CreationFilter, but this would be tricky, especially in the case where the column width is too small for the items to appear on one line.
Hello again.
As long as the items are on one line, the CreationFilter for this is not too bad. I whipped up some quick sample code that seems to work.
public class OptionSetCenteredCreationFilter : IUIElementCreationFilter { void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { if (parent is OptionSetEmbeddableUIElement) { int totalItemWidth = 0; List<OptionSetOptionButtonUIElement> optionSetOptionButtonUIElements = new List<OptionSetOptionButtonUIElement>(); foreach (UIElement childElement in parent.ChildElements) { OptionSetOptionButtonUIElement optionSetOptionButtonUIElement = childElement as OptionSetOptionButtonUIElement; if (null == optionSetOptionButtonUIElement) { Debug.Fail("A child element of the OptionSetEmbeddableUIElement is not an OptionSetOptionButtonUIElement; unexpected."); continue; } totalItemWidth += optionSetOptionButtonUIElement.Rect.Width; optionSetOptionButtonUIElements.Add(optionSetOptionButtonUIElement); } int x = parent.Rect.X; x += (parent.Rect.Width - totalItemWidth) / 2; foreach (OptionSetOptionButtonUIElement optionSetOptionButtonUIElement in optionSetOptionButtonUIElements) { optionSetOptionButtonUIElement.Rect = new Rectangle( x, optionSetOptionButtonUIElement.Rect.Y, optionSetOptionButtonUIElement.Rect.Width, optionSetOptionButtonUIElement.Rect.Height ); x += optionSetOptionButtonUIElement.Rect.Width; } } } bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { // do nothing. return false; } }
Hi Mike,
That creation filter works perfectly. I didn't try the first solution you presented (making the column fixed width and using ItemOrigin) but it is also a valid option for us. Thank you very much for your help!