5

According to this we can show a DataGridView Column text in vertical orientation. Now my question is how can we make to show all the DataGridView Cell text orientation vertically?

Any help will be appreciated

Community
  • 1
  • 1
  • Have you had a look at [DataGridViewContentAlignment](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcontentalignment.aspx)? – Bob. Nov 16 '12 at 15:43
  • i don't want to change the alignment i want to show the text vertically –  Nov 16 '12 at 15:55

2 Answers2

0

you can use WPF. But if you want to use WinForm you can DevExpress. Aslo DevExpress usrd for WPF

Zhenia
  • 3,939
  • 3
  • 15
  • 15
0

here CellPainting Event used.

private void Form1_Load(object sender, EventArgs e)
    {
    dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
    dataGridView1.ColumnHeadersHeight = 50;
    dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;

    // Here we attach an event handler to the cell painting event
    dataGridView1.CellPainting += new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
    }
        void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            // check that we are in a header cell!
            if (e.RowIndex == -1 && e.ColumnIndex >= 0)
            {
                e.PaintBackground(e.ClipBounds, true);
                Rectangle rect = this.dataGridView1.GetColumnDisplayRectangle(e.ColumnIndex, true);
                Size titleSize = TextRenderer.MeasureText(e.Value.ToString(), e.CellStyle.Font);
                if (this.dataGridView1.ColumnHeadersHeight < titleSize.Width)
                {
                    this.dataGridView1.ColumnHeadersHeight = titleSize.Width;
                }

                e.Graphics.TranslateTransform(0, titleSize.Width);
                e.Graphics.RotateTransform(-90.0F);

                // This is the key line for bottom alignment - we adjust the PointF based on the 
                // ColumnHeadersHeight minus the current text width. ColumnHeadersHeight is the
                // maximum of all the columns since we paint cells twice - though this fact
                // may not be true in all usages!   
                e.Graphics.DrawString(e.Value.ToString(), this.Font, Brushes.Black, new PointF(rect.Y - (dataGridView1.ColumnHeadersHeight - titleSize.Width) , rect.X));

                // The old line for comparison
                //e.Graphics.DrawString(e.Value.ToString(), this.Font, Brushes.Black, new PointF(rect.Y, rect.X));


                e.Graphics.RotateTransform(90.0F);
                e.Graphics.TranslateTransform(0, -titleSize.Width);
                e.Handled = true;
            }
        }
nanda9894
  • 61
  • 5