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