GridView FontSize of Q3 2007 SP1

9 posts, 0 answers
  1. Tobin
    Tobin avatar
    9 posts
    Member since:
    Oct 2007

    Posted 05 Jun 2008 Link to this post

    Hi Telerik Team,

    I am currently using Q3 2007 SP1. I have poblem with the fontsize of the GridView. I try to change the fontsize through visual style builder (the edit element). It works fine when design. However, on runtime, it prompts me error of index and the fontsize back to as the default.
    Please clarify if this problem existed in the version i mentioned.
    Thanks in advance

    -Tobin-
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 06 Jun 2008 Link to this post

    Hello Tobin,

    Thank you for the question.

    Because the grid elements are created dynamically, you cannot change their properties through the Element Hierarchy Editor.

    You should do this at run-time through the code.

    If you want to change the font size of header cells, you could use this:

    for (int i = 0; i < this.radGridView1.MasterGridViewInfo.TableHeaderRow.Cells.Count; i++) 
        this.radGridView1.MasterGridViewInfo.TableHeaderRow.Cells[i].CellElement.Font = 
            new Font(this.radGridView1.MasterGridViewInfo.TableHeaderRow.Cells[i].CellElement.Font.FontFamily, 25); 

    If you want to change font size of data cells, you could handle the CellFormating event as follows:

    private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) 
        e.CellElement.Font = new Font(e.CellElement.Font.FontFamily, 25); 

    I hope this helps. If you need additional assistance, do not hesitate to contact me again.

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Tobin
    Tobin avatar
    9 posts
    Member since:
    Oct 2007

    Posted 09 Jun 2008 Link to this post

    Thanks for the fast response.
    It works fine after i add the code as stated.
  4. kumar
    kumar avatar
    6 posts
    Member since:
    Jul 2008

    Posted 06 Oct 2008 Link to this post

    I understood how to change header font programatically. The problem is where to do it.
    I have a derived gridview from RadGridView.
    If I try to change header font in the constructor, it throws exception as CellElement (in cell.CellElement) is null.
    I need to changed header fonts after the grid is fully initialized. After which event handler should I change it.
    I have CellFormatting event handler which I use to change the font of data rows. But somehow header row cells do not fire this event. After loading if i click on any cell, the corresponding header gets the new font.

    Here is code snippet:
    public partial class CPRadGrid : RadGridView
    {
    public CPRadGrid()
    {
    InitializeComponent();
    this.CellFormatting += new CellFormattingEventHandler(CPRadGrid_CellFormatting);
    ...............
    ...............
    }

    void CPRadGrid_CellFormatting(object sender, CellFormattingEventArgs e)
    {
    e.CellElement.Padding = new Padding(4, 0, 2, 0);
    e.CellElement.Font =
    new Font("Segoe UI", 9);
    }

    Any other suggestion for changing font is welcome.

  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 06 Oct 2008 Link to this post

    Hello kumar,

    Thank you for writing.

    You are seeing the exception when trying to change the header font in the constructor, because RadGridView has not initialized its components yet. You could try to change the header text size in the Form_Load event. Just add a public method SetHeaderFont in your CPRadGrid class (use my example code to do this) and call it in the Load event.

    Please, let me know if this does not suit to your scenario.
     

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. ranganadh
    ranganadh avatar
    4 posts
    Member since:
    Apr 2011

    Posted 28 Sep 2011 Link to this post

    Hello,

    I have this code to update the font

    private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) 
        e.CellElement.Font = new Font(e.CellElement.Font.FontFamily, 25);
          //e.CellElement.Font = new Font(e.CellElement.Font.FontFamily, 24, FontStyle.Bold);
    }

    We set font size depending on some conditions in the above event. It works great in my machine. I even tested in some other development machines and it works fine.

    But when I deployed in the clients machine, it throws a null reference exception in the above line to set the font. The scenario is , we have a rad grid displaying some data and the server will send a broadcast message to the win form which has this grid. Whenever we get a broadcast to client application we update the grid item and the cellFormatting event will be fired. Here it creashes.

    THe grid uses the "Segoe UI" font as default in design mode. And when I see the debug information, it says the font name "Segoe UI" is not available. If it is not available it should give error for the first time when the form loads, but it works. WHen there is an update and redrawing the grid gives error.

    {Name = The name 'name' does not exist in the current context} base {System.MarshalByRefObject}: {Name = The name 'name' does not exist in the current context} Name: "Segoe UI"

    Can you give any suggesions on why it happens or anyone experienced this type of issue.

    Thanks,
    Ranganadh.
  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 30 Sep 2011 Link to this post

    Hi Ranganadh,

    Thank you for writing.

    Since I am missing your solution I cannot be sure what the exact reason for the reported issue is. Most probably you are missing the font on this particular machine (Segoe UI is not included in Windows XP by default). To resolve the issue you can try to installing the missing font or use another one.

    In addition, I would not recommend creating a new Font on every CellFormating call. Creating a new font is an expensive operation in terms of memory usage and you can easily run out of memory if you have large grid data. Instead, define your fonts as readonly fields:
    private readonly Font normalFont = new Font("Arial", 8);
    private readonly Font largeFont = new Font("Arial", 12);
     
    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.RowIndex % 2 == 0)
        {
            e.CellElement.Font = this.normalFont;
        }
        else
        {
            e.CellElement.Font = this.largeFont;
        }
    }

    Write me back if you have any other questions. 

    Best wishes,
    Martin Vasilev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Vishal Mehta
    Vishal Mehta avatar
    1 posts
    Member since:
    Sep 2009

    Posted 05 Oct 2011 Link to this post

    Hello,

    I implemented the solution you provided and I am getting the following errors intermittently. It runs for 10 mins and then crashes. Below is the stack trace:

    System.NullReferenceException was unhandled
      Message=Object reference not set to an instance of an object.
      Source=Telerik.WinControls
      StackTrace:
           at Telerik.WinControls.Layouts.ContextLayoutManager.LayoutQueue.RemoveOrphans(RadElement parent)
           at Telerik.WinControls.Layouts.ContextLayoutManager.LayoutQueue.Add(RadElement e)
           at Telerik.WinControls.RadElement.InvalidateMeasure(Boolean recursive)
           at Telerik.WinControls.RadElement.InvalidateMeasure()
           at Telerik.WinControls.RadElement.OnLayoutPropertyChanged(RadPropertyChangedEventArgs e)
           at Telerik.WinControls.RadElement.OnPropertyChanged(RadPropertyChangedEventArgs e)
           at Telerik.WinControls.VisualElement.OnPropertyChanged(RadPropertyChangedEventArgs e)
           at Telerik.WinControls.RadComponentElement.OnPropertyChanged(RadPropertyChangedEventArgs e)
           at Telerik.WinControls.RadItem.OnPropertyChanged(RadPropertyChangedEventArgs e)
           at Telerik.WinControls.UI.UIItemBase.OnPropertyChanged(RadPropertyChangedEventArgs e)
           at Telerik.WinControls.UI.LightVisualElement.OnPropertyChanged(RadPropertyChangedEventArgs e)
           at Telerik.WinControls.UI.GridVirtualizedCellElement.OnPropertyChanged(RadPropertyChangedEventArgs e)
           at Telerik.WinControls.RadObject.RaisePropertyNotifications(RadPropertyValue propVal, Object oldValue, Object newValue, ValueSource oldSource)
           at Telerik.WinControls.RadObject.SetValueCore(RadPropertyValue propVal, Object propModifier, Object newValue, ValueSource source)
           at Telerik.WinControls.RadElement.SetValueCore(RadPropertyValue propVal, Object propModifier, Object newValue, ValueSource source)
           at Telerik.WinControls.RadObject.SetValue(RadProperty property, Object value)
           at Telerik.WinControls.VisualElement.set_Font(Font value)
           at PatTrack.WinClient.Entities.MultiSiteGridItemList.multiSiteGrid_CellFormatting(Object sender, CellFormattingEventArgs e) in C:\Dev\PatTrack\trunk\PatTrack.WinClient\Entities\MultiSiteGridItemList.cs:line 228
           at Telerik.WinControls.UI.CellFormattingEventHandler.Invoke(Object sender, CellFormattingEventArgs e)
           at Telerik.WinControls.UI.RadGridViewElement.OnCellFormatting(Object sender, CellFormattingEventArgs e)
           at Telerik.WinControls.UI.GridDataCellElement.OnCellFormatting(CellFormattingEventArgs e)
           at Telerik.WinControls.UI.GridDataCellElement.OnViewCellFormatting(CellFormattingEventArgs e)
           at Telerik.WinControls.UI.GridCellElement.UpdateInfo()
           at Telerik.WinControls.UI.GridRowElement.UpdateInfo()
           at Telerik.WinControls.UI.GridDataRowElement.UpdateInfo()
           at Telerik.WinControls.UI.GridTableElement.UpdateCellContent(GridViewRowInfo rowInfo)
           at Telerik.WinControls.UI.GridTableElement.UpdateWhenItemChanged(DataViewChangedEventArgs args)
           at Telerik.WinControls.UI.GridTableElement.UpdateViewCore(Object sender, DataViewChangedEventArgs args)
           at Telerik.WinControls.UI.GridTableElement.UpdateView(Object sender, DataViewChangedEventArgs args)
           at Telerik.WinControls.UI.GridTableElement.ProcessTemplateEvent(GridViewEvent eventData)
           at Telerik.WinControls.UI.GridTableElement.Telerik.WinControls.UI.IGridViewEventListener.ProcessEvent(GridViewEvent eventData)
           at Telerik.WinControls.UI.GridViewEventProcessEntity.ProcessCollection(GridViewEvent gridEvent, PriorityWeakReferenceList list, GridEventProcessMode processMode)
           at Telerik.WinControls.UI.GridViewEventProcessEntity.Process(GridViewEvent gridEvent)
           at Telerik.WinControls.UI.GridViewEventProcessEntity.ProcessEvent(GridViewEvent gridEvent)
           at Telerik.WinControls.UI.GridViewSynchronizationService.NotifyListeners(GridViewEvent gridEvent)
           at Telerik.WinControls.UI.GridViewSynchronizationService.FlushEvents()
           at Telerik.WinControls.UI.GridViewSynchronizationService.DispatchEvent(GridViewEvent gridEvent)
           at Telerik.WinControls.UI.GridViewSynchronizationService.DispatchEvent(GridViewTemplate template, GridViewEvent eventData, Boolean postUI)
           at Telerik.WinControls.UI.GridViewTemplate.DispatchEvent(GridViewEvent gridEvent, Boolean postUI)
           at Telerik.WinControls.UI.GridViewTemplate.DispatchDataViewChangedEvent(Object sender, DataViewChangedEventArgs args)
           at Telerik.WinControls.UI.GridViewTemplate.OnViewChanged(Object sender, DataViewChangedEventArgs e)
           at Telerik.WinControls.UI.GridViewTemplate.OnViewChanged(DataViewChangedEventArgs e)
           at Telerik.WinControls.UI.GridViewTemplate.CollectionView_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
           at Telerik.WinControls.Data.RadCollectionView`1.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
           at Telerik.WinControls.Data.RadCollectionView`1.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
           at Telerik.WinControls.Data.RadDataView`1.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
           at Telerik.WinControls.Data.RadCollectionView`1.source_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
           at Telerik.WinControls.Data.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
           at Telerik.WinControls.Data.RadListSource`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
           at Telerik.WinControls.Data.RadListSource`1.ChangeItem(Int32 index, TDataItem item, String propertyName)
           at Telerik.WinControls.Data.RadListSource`1.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
           at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
           at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
           at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
           at System.ComponentModel.BindingList`1.Child_PropertyChanged(Object sender, PropertyChangedEventArgs e)
           at PatTrack.WinClient.Entities.MultiSiteGridItem.OnPropertyChanged(String info) in C:\Dev\PatTrack\trunk\PatTrack.WinClient\Entities\MultiSiteGridItem.cs:line 363
           at PatTrack.WinClient.Entities.MultiSiteGridItem.Update(SiteDetails newSiteDetails) in C:\Dev\PatTrack\trunk\PatTrack.WinClient\Entities\MultiSiteGridItem.cs:line 430
           at PatTrack.WinClient.Entities.MultiSiteGridItemList.Update(List`1 list) in C:\Dev\PatTrack\trunk\PatTrack.WinClient\Entities\MultiSiteGridItemList.cs:line 259
           at PatTrack.WinClient.Net.WinServerConnection.ThreadPool_MultiSiteGridBroadcastWorkItem(Object broadcast) in C:\Dev\PatTrack\trunk\PatTrack.WinClient\Net\WinServerConnection.cs:line 528
           at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
           at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
           at System.Threading.ThreadPoolWorkQueue.Dispatch()
           at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
      InnerException:

    Please provide some insight on what could be causing this exception.
    Thanks,
    Vishal
  9. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 07 Oct 2011 Link to this post

    Hi Vishal,

    The stack-trace is not sufficient to track down the reason for described exception. I need to investigate your particular scenario and code in order to assist you further. Please open a new support ticket and send me a small project, which demonstrates your approach and the exception.

    Regards,
    Martin Vasilev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top