Is there a way to force a DataGridView to fire its CellFormatting event for all cells?

前端 未结 5 1460
北荒
北荒 2020-12-16 15:09

We use the CellFormatting event to colour code cells in various grids all over our application.

We\'ve got some generic code which handles export to Excel (and print

5条回答
  •  执笔经年
    2020-12-16 15:44

    Assuming, as @DavidHall suggests, there is no magic .FormatAllCells our only option is to stop using CellFormatting.

    However, new problem here is that applying cell style formatting during load doesn’t seem to have any effect. Lots of posts out there if you Google it. Also they point out that if you put the same code under a button on the form and click it after loading (instead of in the load, the code will work ... so the grid has to be visible before styling can apply). Most advice on the topic suggests you use ... drumroll ... CellFormatting. Aargh!

    Eventually found a post which suggests using the DataBindingComplete event of the grid. And this works.

    Admittedly, this solution is a variant of my unwanted option "4".

提交回复
热议问题