Flexgrid font name

Posted by: tobyschlank on 26 February 2018, 6:37 am EST

    • Post Options:
    • Link

    Posted 26 February 2018, 6:37 am EST

    Hi,

    Is there a way to only set the flexgrid text font name on a range of cells?

    All the examples i’ve seen also include the text size and bold etc. with the code, and i do not want to set these here.

    I need to only change the font name on a range of cells.

    Thank you

  • Posted 27 February 2018, 4:45 am EST

    Hi Toby,

    this is not possible unfortunately, you always have to set the full “Font” object.

    Best regards

    Wolfgang

  • Posted 27 February 2018, 7:42 am EST

    Hello Toby,

    As Wolfgang correctly mentioned, there is no overload of Font class constructor that only takes the font family name.

    The best you can do is fetch the old cell style and just modify the font family without disturbing other settings for the cells within the CellRange, as follows:

    CellStyle preAppliedStyle = _flexGrid.Styles.Add("CellSize");
    preAppliedStyle.Font = new Font("Verdana", 16);
    preAppliedStyle.BackColor = Color.LightGreen;
    _flexGrid.SetCellStyle(3, 2, preAppliedStyle);
    
    CellRange rg = _flexGrid.GetCellRange(2, 2, 10, 10);
    ChangeFontName(rg, "Magneto");
    
    public void ChangeFontName(CellRange rg, string name)
    {
          CellStyle fontNameStyle = _flexGrid.Styles.Add("MyStyle");
          for(int i = rg.r1; i <= rg.r2; i++)
          {
               for(int j=rg.c1; j <= rg.c2; j++)
               {
                   if (_flexGrid.GetCellStyle(i, j) == null)
                   {
                        fontNameStyle.Font = new Font(name, _flexGrid.Font.Size);
                        _flexGrid.SetCellStyle(i, j, fontNameStyle);
                   }
                   else
                   {
                        _flexGrid.GetCellStyle(i, j).Font = new Font(name, _flexGrid.GetCellStyle(i, j).Font.Size);
                    }
              }
         }
    }
    

    Regards,

    Ruchir Agarwal

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels