views:

324

answers:

2

I have a DataGridView in readonly mode in a .NET 3.5 (Visual Studio 2008) WinForms application.

The cells' width is very small. Some of the cells contain a short number. Now, even with a small font, sometimes the number is shown with an ellipsis. For example "8..." instead of "88".

Is there a way to let the text flow over the next cell in a standard DataGridView and avoid the ellipsis?

Thanks!

A: 

No, there's probably some property to disable the ellipsis (if you access the underlying controls), but flow over (and also cell merging) is not supported in the standard DataGridView.

MartinStettner
A: 

handle the DataGridView control's CellPainting event. Check the following link :

http://msdn.microsoft.com/en-us/library/hta8z9sz.aspx

Note that when you draw the text itself you need to customize the StringFormat -

quote from the MSDN code :

if (e.Value != null)

{

                e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                    Brushes.Crimson, e.CellBounds.X + 2,
                    e.CellBounds.Y + 2, StringFormat.GenericDefault);
            }

Use the following StringFormat object instead of StringFormat.GenericDefault :

StringFormat strFormat = new StringFormat();

strFormat.Trimming = StringTrimming.None;

Regards

David Elie