Flexgrid font size

Posted by: tobyschlank on 1 November 2018, 10:06 pm EST

    • Post Options:
    • Link

    Posted 1 November 2018, 10:06 pm EST

    Hi,

    I am using VB.Net and ComponentOne 2017.2.1.5.

    I am having trouble setting the text size in the grid using styles.

    The following does work:

    
    fontname = "Arial"
    fontsize = 50
    Dim csc As CellStyle = Me.fa.Styles.Add("Style")
    csc.Font = New Font(fontname , fontsize , FontStyle.Bold)
    Dim crhc As CellRange = Me.fa.GetCellRange(1, 1, Me.fa.Rows.Count - 1, Me.fa.Cols.Count - 1)
    crhc.Style = csc
    
    

    The following does NOT works:

    (the fontsize values come from Microsoft SQL Server. This field is an integer.)

    
    fontname = "Arial"
    fontsize = ds.Tables("fontsizeTable").Rows(index).Item("fontsize") 
    Dim csc As CellStyle = Me.fa.Styles.Add("Style")
    csc.Font = New Font(fontname , fontsize , FontStyle.Bold)
    Dim crhc As CellRange = Me.fa.GetCellRange(1, 1, Me.fa.Rows.Count - 1, Me.fa.Cols.Count - 1)
    crhc.Style = csc
    
    

    Regardless of the fontsize value, the size is always the default grid size.

    Am i missing something?

    Any help is greatly appreciated.

    Thanks

  • Posted 4 November 2018, 2:54 pm EST - Updated 3 October 2022, 1:38 pm EST

    Hi,

    I couldn’t replicate your observations at my end. I used a font DataTable created at runtime, and the rest of the code is exactly like yours. You can see the result I got in the attached image.

    The font is changed for then non-fixed cells.

    You can also find the sample that I used in the attachments. Please see if there is anything else you are doing differently and modify the attached sample, so I can replicate the issue and help you further.

    FontSizeFromDB.zip

  • Posted 5 November 2018, 9:44 pm EST

    Thank you very much for your reply. I was able to follow your sample and everything works well now.

    Another question,

    If i have a style such as:

    
    cs = Me.fa.Styles.Add("myStyle3") 
    cs.Font = New Font("Arial", 100)
    Me.myGrid.SetCellStyle(4, 4, "myStyle3")
    
    

    then as some stage later in my program, i need to change the colour of the same cell (or perform some other style changes), when i use:

    
    cs = Me.fa.Styles.Add("myStyle4")
    cs.BackColor = Color.Red
    Me.myGrid.SetCellStyle(4, 4, "myStyle4")
    

    The text size returns to default. Is there a way to keep the current style and edit the required cells?

    Thanks

  • Posted 5 November 2018, 10:54 pm EST

    Hi,

    You can create a new cell style based on another cell style. The new cell style will then inherit already set properties from the cell style it is based on.

    In your example, you can do something like this:

    cs = Me.fa.Styles.Add("myStyle3") 
    cs.Font = New Font("Arial", 100)
    Me.myGrid.SetCellStyle(4, 4, "myStyle3")
    
    cs = Me.fa.Styles.Add("myStyle4", "myStyle3")
    cs.BackColor = Color.Red
    Me.myGrid.SetCellStyle(4, 4, "myStyle4")
    

    You can refer to the attached sample where I’ve modified my previous sample to include this change.

    Regards,

    Jitender

    FontSizeFromDB_Modified.zip

  • Posted 6 November 2018, 11:30 am EST

    Thanks for your reply.

    Is it possible to add a style to a cell or group of cells that already contain a style but it’s name is not known?

    In the example you provided, the style name had to be already known.

    Ideally, i would like to add a style to cells regardless of whether it already has a style or not.

    Is this possible?

    Thanks

  • Posted 6 November 2018, 7:39 pm EST

    Hi Toby,

    attached is a sample which contains a helper class “HGFlexGridStyleHandler”: this style handler allows modification of the style elements of specific cells. It internally creates styles on the fly, but you don’t have to care about styles: just set and combine back color, fore color, font and other style elements on the fly for specific cells.

    Hope that this helper class is helpful and understandable ;-).

    FlexGridStyleHandler.zip

    Best regards

    Wolfgang

  • Posted 7 November 2018, 10:13 am EST

    Thanks Wolfgang for your reply.

    Is there a VB.Net equivalent version of the FlexGridStyleHandler?

    Regards,

    Toby

  • Posted 7 November 2018, 7:44 pm EST

    Hi Toby,

    attached is the vb sample. Note: I used this converter to create it http://converter.telerik.com/ - hopefully there are no problems introduced by this ;-).

    FlexGridStyleHandlerVB.zip

    Best regards

    wolfgang

  • Posted 7 November 2018, 10:44 pm EST

    Wolfgang, thanks for your solutions.

    Toby, you can get Style name for any cell by using GetCellStyle method. So, you can also write:

    cs = Me.fa.Styles.Add("myStyle4", Me.myGrid.GetCellStyle(4, 4))
    cs.BackColor = Color.Red
    Me.myGrid.SetCellStyle(4, 4, "myStyle4")
    

    Regards,

    Jitender

  • Posted 8 November 2018, 9:18 pm EST

    Thank you Wolfgang and Jitender for you replies.

    I will test your suggestions in the coming days.

    Regards,

    Toby

  • Posted 25 February 2022, 5:30 am EST

  • Posted 5 March 2024, 6:55 am EST

Need extra support?

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

Learn More

Forum Channels