代码之家  ›  专栏  ›  技术社区  ›  nakiya

已剪裁devexpress repositoryitemroGroup项文本

  •  1
  • nakiya  · 技术社区  · 7 年前

    RepositoryItemRadioGroup XtraGrid.GridControl 单元格编辑。

            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);
            }
    

    跑步时, RadioGroupItem 的文本如果超过某些字符数,则会在右侧被剪裁。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Hambone    7 年前

    最初我会说使用“AutoFit”来实现这一点,但在提出建议之前,我尝试过它,它似乎自动适应了内容而不是控件。

    ItemsLayout 存储库的属性编辑为“Flow”,这将使单选按钮彼此相邻,而不是根据最大的标题为它们留出空间:

    repositoryItemRadioGroup1.ItemsLayout = DevExpress.XtraEditors.RadioGroupItemsLayout.Flow
    

    下一部分是黑客,可能需要一些调整。。。实际上,您需要根据单选项标题和单选按钮手动计算列的宽度。带有填充的单选按钮本身的宽度大约为25。每个字符可能是5或6。因此,如果您接受每个项目并假设它需要25 x字符的宽度,您可以将其相加并相应地设置列宽。

    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;