C# 更改Telerik GRICVIEWCOMBOX附加列表字体

C# 更改Telerik GRICVIEWCOMBOX附加列表字体,c#,winforms,telerik,radgridview,datagridviewcombobox,C#,Winforms,Telerik,Radgridview,Datagridviewcombobox,我有一个带有组合框列的Telerik GridView,在这个组合框中过滤一个下拉的附加列表 与下图相同 所以我想把附加列表的字体放大 如何操作?您可以使用字体制作CellTemplate,也可以处理CellFormatting事件并执行类似操作: void radGridView_CellFormatting(object sender, CellFormattingEventArgs e) { // For all cells under the Account N

我有一个带有组合框列的Telerik GridView,在这个组合框中过滤一个下拉的附加列表

与下图相同

所以我想把附加列表的字体放大


如何操作?

您可以使用字体制作CellTemplate,也可以处理
CellFormatting
事件并执行类似操作:

void radGridView_CellFormatting(object sender, CellFormattingEventArgs  e)      
{ 
    // For all cells under the Account Name column
    if(e.CellElement.ColumnInfo.Name == "Account Name")
    {
        if(e.CellElement.Value != null)
        {
            System.Drawing.Font newfontsize = new System.Drawing.Font(e.CellElement.Font.FontFamily.Name,20);

            for each(GridViewCellInfo cell in e.Row.Cells)
            {
                e.CellElement.Font = newfontsize;
            }

        }
    }
    // For all other cells under other columns
    else
    {
        e.CellElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.Font, Telerik.WinControls.ValueResetFlags.Local);
    }
}

为“newfontsize”变量插入所需的任意大小的字体。还请注意,在您的情况下可能不需要else语句,但您可以使用ResetValue属性将字体重置为默认值。

RadDropDownList使用不同的弹出窗口来表示其默认项和自动完成的建议项。下面是一个示例,演示如何更改这两种字体:

 void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
        if (editor != null)
        {
            editor.DropDownStyle = RadDropDownStyle.DropDown;
            RadDropDownListEditorElement element = (RadDropDownListEditorElement)editor.EditorElement;

            element.VisualItemFormatting -= element_VisualItemFormatting;
            element.AutoCompleteSuggest.DropDownList.VisualItemFormatting -= element_VisualItemFormatting;

            //this handles the default drop down formatting - when you press the arrow key to open the drop down
            element.VisualItemFormatting += element_VisualItemFormatting;
            //this handles the suggest popup formatting
            element.AutoCompleteSuggest.DropDownList.VisualItemFormatting += element_VisualItemFormatting;
        }
    }

    void element_VisualItemFormatting(object sender, VisualItemFormattingEventArgs args)
    {
        args.VisualItem.Font = new Font("Arial", 16);
    }

如果您查看了文档站点,我相信您将能够找到一些示例。还有您可以设置的自定义字体属性吗?谢谢@glace的帮助,但很抱歉它根本不起作用,您误解了我的意思。我想要的是放大下拉列表中的字体。这是当我开始在组合框内键入(搜索)时弹出的列表。没有放大单元格内的字体…哦,我错了。您可以访问附加到该事件的基础列表吗?可能将发送者强制转换为DataGridComboBoxCell(或类似的东西),然后查看是否可以遍历ComboBox的项目列表并更改其格式属性。如果有机会的话,我会再仔细研究一下。非常感谢,它做得很好。但我还有一个问题。如何增加建议弹出列表的宽度。或者如何使其适合建议弹出列表中最长的字符串。任何一个都可以。再次感谢!抱歉耽搁了。下面是如何设置建议弹出窗口的最小宽度:element.AutoCompleteSuggest.DropDownList.DropDownMinSize=new System.Drawing.Size(200,0);要计算最长项目的宽度,可以使用TextRenderer.MeasureText方法。