Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2005
Show pound signs if cell is too small to show a number
posted

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

Parents
  • 469350
    Suggested Answer
    Offline posted

    Hi Shaolin,

    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.

    MemDataTable CS 2010.zip
Reply Children