devexpress RepositoryItemRadioGroup item text clipped

244 Views Asked by At

I'm creating a RepositoryItemRadioGroup on an XtraGrid.GridControl cell edit.

        var radioGroup = new RepositoryItemRadioGroup();

        var radioCtrl = node.ViewControl as IRadioButtonControl;
        if (radioCtrl == null)
            return radioGroup;

        var index = 0;
        foreach (var choice in choices)
        {
            var choiceValue = index.ToString();
            ++index;
            var item = new RadioGroupItem(choiceValue, choice);
            radioGroup.Items.Add(item);
        }

When run, RadioGroupItem's text gets clipped on the right if it is longer than some number of characters.

How to control/change painting of this control?

1

There are 1 best solutions below

2
Hambone On

I would have initially said to use "AutoFit" to make this work, but I tried it before suggesting it and it appears it autofits on the content rather than the control.

There is a hack, of sorts, I think would come close. First of all, you need to set the ItemsLayout property of the repository edit to "Flow," which will make the radio buttons appear next to each other rather than making them space based on the largest caption:

repositoryItemRadioGroup1.ItemsLayout = DevExpress.XtraEditors.RadioGroupItemsLayout.Flow

This next part is the hack and may take some tweaking... you essentially need to manually figure out the width of the column based on the radio item captions and the radio buttons. The radio button itself with padding is roughly a width of 25. Each character is probably a 5 or a 6. So, if you take each item and assume it needs a width of 25 x the # of characters, you can add that up and set the column width accordingly.

int width = 0;
foreach (var choice in choices)
{
    var choiceValue = index.ToString();
    width += (25 + 6 * choice.Length);
    ++index;
    var item = new RadioGroupItem(choiceValue, choice);
    repositoryItemRadioGroup1.Items.Add(item);
}

colGridColumn.Width = width;

I hope there is a Dev Ex solution to this, but I don't know of one... and in the meantime give this a try.