C1TrueDBGrid -- how to read cell style

Posted by: adam.dawes on 19 June 2018, 7:27 pm EST

    • Post Options:
    • Link

    Posted 19 June 2018, 7:27 pm EST

    Hello,

    I have a C1TrueDBGrid whose content has been styled using the FetchRowStyle event. I need to be able to later read the style details (such as the BackgroundColor) for individual cells within the grid, but I can’t find any way to do this.

    I can see a GetCellStyle method in the C1.Win.C1TrueDBGrid.BaseGrid.View class, but this is a protected internal method that I can’t invoke. Is there any way to get access to this functionality?

    Thanks!

  • Posted 20 June 2018, 5:41 pm EST

    Hi,

    You can use reflection to invoke the protected internal method and access Style of an individual cell.

    
    var method = _trueDB.Splits[0].GetType().GetMethods  (System.Reflection.BindingFlags.NonPublic |
                   System.Reflection.BindingFlags.Instance).Where(m => m.Name.Contains("GetCellStyle")).
                   First();
    var style = method.Invoke(_trueDB.Splits[0], new object[] { row, col,   _trueDB.Columns[col].CellText(row), false });
    
    

    Please find the attached sample demonstrating the same.

    Thanks,

    Pragati

    ReadCellStyle.zip

  • Posted 20 June 2018, 6:48 pm EST

    Hi Pragti,

    Thanks very much for the reply – reflection was going to be my fallback in the absence of any “proper” way to achieve this, so your approach backs up my assumption that no other way may be available.

    I’m puzzled as to why this isn’t exposed as a public method of the grid however, this would be a useful addition for a future version.

    Best regards,

    Adam.

  • Posted 21 June 2018, 4:57 pm EST

    Hi Adam,

    We have sent a request [TFS: 328862] to make the method public and it would be done so, if they find it feasible.

    Meanwhile, there is one more way of getting the cell style of any specific cell at run time, which is using OwnerDrawCell event. This event fires before a cell is rendered, hence you may use its e.CellStyle for any cell. The disadvantage with this approach is, this event fires for all cells, so even if you want to check for one specific cell it will be triggered for all cell withing grid.

    You can find more information about this at: http://helpcentral.componentone.com/nethelp/c1truedbgrid/ownerdrawncells.html

    Thanks,

    Ruchir

  • Posted 15 November 2018, 7:21 pm EST

    Hi Adam!

    Glad to inform you, the GetCellStyle method has been added to the C1TrueDbGrid Split in the latest builds of 2018v3. To see the same, please download the builds from here: http://prerelease.componentone.com/dotnet40/c1winforms/2018-t3/C1WinForms.4_4.0.20183.338.zip, or update using C1Live utility.

    Regards,

    Meenakshi

Need extra support?

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

Learn More

Forum Channels