Hi,
What is the best way (if there is any) to show pound signs instead of a number if a cell is not wide enough to display the whole formatted number? This is one of features in MS Excel. In order to do this, we need to be able to do at least the following tasks:
1) get the formatted number
2) get the font
3) get Graphics instance to call MeasureString on the formatted number with the font
4) get the width of the cell and it margins
Thanks,
Shaolin
Hi Mike,
I specified a text format of "#,##0.00" on the one of columns of double data type:
band.Columns[7].Format = "#,##0.00";
Even the column was wide enough, pound signs were still displayed for some cells in this column. When I hovered mouse over the cell, the cell is repainted and pound signs were changed to the real number. I could even see pound signs in Key and string columns, especially when I played with horizontal scroll bar.
Hi Shaolin,
Under what circumstances is it not accurate? It seems to be working fine in my sample. If I resize a column, I can see it showing the text when the column is wide enough to fit the text and showing # signs when it's not.
Thanks for your quick response and solution!
I tested your solution. Method IsTextFullyVisible is not always accurate.
Regards,
Measuring the test yourself will be extremely difficult. But there might be an easier way. The grid and it's editors already keep track of whether or not the text fits inside the cell. They do this so the grid knows whether or not it's appropriate to show a tooltip.
So you could probably make use of that and then use a CreationFilter in order to change the Text of the cell to whatever you want without affecting the cell's value.
I decided to try to whip up a quick sample and it turned out to be surprisingly easy. My sample is attached here.