Skip to main content

Row height and font

Comments

11 comments

  • Dapfor Team

    Hello,

    Did you see the Row.Adjust() method?

    Regards,
    Dapfor

    0
  • Cory Rainbeau

    Why doesn't the row height adjust automatically to fit the specified row font?

    0
  • Dapfor Team

    This may not always be desirable. If the grid is constantly doing the adjustment and the programmer does not want to, he won’t able to keep the original size of rows.
    But it is easy to implement using the grid’s API:

     


    //Change the font:
    header.Appearance.RowFont = ...;

    //Adjust all visible rows
    for(int i = 0; i < grid.Rows.Count; ++i)
    {
        Row row = grid.Rows[i];
        row.Adjust();
    }

    //Adjust when a new row is added:
    grid.RowAdded += delegate(object sender, GridRowEventArgs e)
    {
        e.Row.Adjust();
    };

    Best regards,

    Dapfor



    0
  • Cory Rainbeau

    I had originally done what you just suggested, but I also had to add the Adjust() call in the PaintRow event since the height went back to the original height when a row was updated.

    0
  • Dapfor Team

    Adjusting rows in grid.Paint events can have a negative impact on the performance. Each time when the grid paints cells, it will measure the optimal size. At which moment do you change the font’s weight - when the row is updated or painted? And how much rows do you have in the grid?

    Regards,

    Dapfor

    0
  • Cory Rainbeau

    I updated my code so that the Adjust() call is made in the RowUpdated event instead. Not sure why I didn't think of that before.

    Thanks.

    0
  • Dapfor Team

    We think this will be more performant comparing to Grid.PaintRow event.

    Dapfor

    0
  • Cory Rainbeau

    One final question. I'm using the grid to track stocks, which are updated many times per second. Is there anyway to set the row height just once, so that the Adjust() call doesn't have to be made on every single row update? The only time the row height needs to change is when the user changes the font for the rows.

    0
  • Dapfor Team

    Hello,

    The response is in our previous post. When the user changes fonts call the following:

    OnFontChanged(object sender, EventArgs e)
    {
    //Adjust all visible rows
    for(int i = 0; i < grid.Rows.Count; ++i)
    {
        Row row = grid.Rows[i];
        row.Adjust();
    }
    }

    Just some notes about Grid.RowUpdated and Grid.PaintRow:

    May be you know that Windows paints the content in two steps:
    1.    It calls the method Control.Invalidate and cumulates a region
    2.    Then it sends a WM_PAINT message.
    I.e it has an asynchronous rendering system. The Control.Invalidate may be called by many times, but the WM_PAINT message will come to redraw the content only once. The minimum interval between two WM_PAINT messages is 15 msec. If the system is overloaded, then WM_PAINT comes less often.  Accordingly, the grid uses this feature for high-performance content displaying.

    When you call Row.Update/Cell.Update or grid receives notification from INotifyPropertyChanged/IBindingList it implicitly calls the Control.Invalidate() method. Grid.RowUpdated callback is called at this stage. The second callback Grid.PaintXXX()is called when a WM_PAINT message arrives and only for rows displayed in visible bounds of the grid.

    Therefore, stocks can be updated as often as needed, without an impact on the application performance.

    Hope, this will help you,

    Dapfor

    0
  • su myat

    Hi,
    I want to change the font and font size of the grid header and hierarchical grid header
    I used the following code to change font and font size.

                    Font TempFont = new Font(l_crFontName, l_nFontSize);    
                    grid1.Headers[0].Appearance.RowFont = TempFont;
                    grid1.Headers[0].Appearance.ColumnCaptionFont = TempFont;
                    grid1.Headers[0].InvalidateRows();


                    grid1.Headers[1].Appearance.RowFont = TempFont;
                    grid1.Headers[1].Appearance.ColumnCaptionFont = TempFont;
                    grid1.Headers[1].InvalidateRows();

    Font size changing for headers [0] is ok. But headers[1] font size does not change as I want.
    Can you suggest me the correct way to change the font size for hierarchical header?
    Thanks in advance.

    Wish everyone happy and successful in upcoming years !
    Best Rgds

    0
  • Dapfor Team

    Hello,

    Happy new year and best wishes in 2013!

    We didn't find any problem with font. Which version of the grid do you use and what behaviour do you expect?

    Best regards,

    Dapfor

     

     

    0

Please sign in to leave a comment.

Powered by Zendesk