当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Change Telerik GricViewComboBox Append List Font

问题描述:

i have a Telerik GridView with a ComboBox Column, while filtering in this Combobox an appending list dropped down.

Same as the image below...

So i want to make the font of the Append list larger.

How to do it?

网友答案:

RadDropDownList uses different popups for its default items representation and for its auto complete suggest items. Here is an example demonstrating how to change the font of both:

 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);
    }
网友答案:

You could either make a CellTemplate with your font, or you could handle the CellFormating event and do something like this:

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

Plug in whatever size font you want for the "newfontsize" variable. Also note that, the else statement may not be necessary in your case, but you can reset the font to default using the ResetValue property.

分享给朋友:
您可能感兴趣的文章:
随机阅读: