 
 
dataGridView Nesnesinde Sütun Başlıklarını Dikey Yazdırma
Merhaba. DataGridView nesnemizdeki sütun başlıklarını dikey konumda yazılmasını sağlayacağız. Bunun için dataGridView1_CellPainting kısmına aşağıdaki kodları yazın.

.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.CellPainting +=new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            
            DataGridViewTextBoxColumn sutun = new DataGridViewTextBoxColumn();
            DataGridViewTextBoxColumn sutun2 = new DataGridViewTextBoxColumn();
            DataGridViewTextBoxColumn sutun3 = new DataGridViewTextBoxColumn();
          
            //sütun başlıklarının yazı rengini değiştiriyoruz 
            sutun.HeaderCell.Style.ForeColor = Color.Black;
            sutun2.HeaderCell.Style.ForeColor = Color.Black;
            sutun3.HeaderCell.Style.ForeColor = Color.Black;
          
            //sütun başlıklarının font değerini değiştiriyoruz
            sutun.HeaderCell.Style.Font = new Font("Tahoma",12,FontStyle.Bold);
            sutun2.HeaderCell.Style.Font = new Font("Tahoma", 12, FontStyle.Bold);
            sutun3.HeaderCell.Style.Font = new Font("Tahoma", 12, FontStyle.Bold);
           
            //sütundaki satırların rengini değiştiriyoruz
            sutun.DefaultCellStyle.ForeColor = Color.Red;
            sutun2.DefaultCellStyle.ForeColor = Color.Blue;
            sutun3.DefaultCellStyle.ForeColor = Color.Green;
            
            //sütundaki satırların font değerini değiştiriyoruz
            sutun.DefaultCellStyle.Font=new Font("Tahoma",12,FontStyle.Bold);
            sutun2.DefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Bold);
            sutun3.DefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Bold);
            sutun.HeaderText = "Sıra No ";
            sutun.Width = 50; 
            sutun2.HeaderText = "Ad";
            sutun2.Width = 100;
            sutun3.HeaderText = "Soyad";
            sutun3.Width = 100;
            dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
            dataGridView1.ColumnHeadersHeight = 80;
            
            //sütunlarımızı ekliyoruz 
            dataGridView1.Columns.Add(sutun);
            dataGridView1.Columns.Add(sutun2);
            dataGridView1.Columns.Add(sutun3);
           
            //datagridimize verileri ekliyoruz
            for (int i = 0; i < 10; i++)
            { 
                dataGridView1.Rows.Add();
                dataGridView1[0, i].Value = (i+1).ToString();
               
                string[] listeAd = {"Bahadır","Fatih","Haluk","Mehmet","Ahmet","Mesut","Veli","Ayhan","Bülent","Rasim"};
                dataGridView1[1, i].Value = listeAd[i];
                string[] listeSoyad = { "ŞAHİN", "KOÇ", "AKMAN", "AYDIN", "SARP", "ALP", "SEÇKİN", "DALKIRAN", "ÖZHAN", "UYGUR" };
                dataGridView1[2, i].Value = listeSoyad[i];
            }
           
        }
        
        private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        { 
           if (e.RowIndex == -1)
           //sütun başlıklarını dikey konuma çeviriyoruz
            { if (e.ColumnIndex> -1) 
            { e.Paint(e.CellBounds, DataGridViewPaintParts.All& ~ DataGridViewPaintParts.ContentForeground); using (SolidBrush br = new SolidBrush(e.CellStyle.ForeColor)) using (StringFormat sf = new StringFormat()) { sf.FormatFlags = StringFormatFlags.DirectionVertical; e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, br, e.CellBounds, sf); } e.Handled = true; } } }
        
    }
}
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN