2013-08-18 34 views
2

我被困在此,如果任何機構可以幫我想打印下面只喜歡一個虛線datagridview的標題行:如何設置在C#中自定義的DataGridView國界的WinForms

Name    ID 
--------------------- 

並打印項目沒有這樣的

Name    ID 
--------------------- 
Abc    21 

anyborders我用這個代碼

dgvmain.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; 
dgvmain.CellBorderStyle = DataGridViewCellBorderStyle.None; 

dgvmain是我的名字DataGridView 任何幫助提前感謝。

+0

爲什麼不截屏? –

+0

抱歉沒有讓你@金王 – ROM

+1

我想你應該發佈一些屏幕截圖(至少一個鏈接到你想要的屏幕截圖)。 –

回答

6

您需要通過將代碼添加到CellPainting事件處理程序來進行一點自定義繪畫。對於設置在小區邊界到None,使用CellBorderStyle

dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None; 

// CellPainting event handler for your dataGridView1 
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
{ 
    if (e.RowIndex == -1 && e.ColumnIndex > -1) 
    { 
     e.Handled = true; 
     using (Brush b = new SolidBrush(dataGridView1.DefaultCellStyle.BackColor)) 
     { 
     e.Graphics.FillRectangle(b, e.CellBounds); 
     } 
     using (Pen p = new Pen(Brushes.Black)) 
     { 
     p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; 
     e.Graphics.DrawLine(p, new Point(0, e.CellBounds.Bottom-1), new Point(e.CellBounds.Right, e.CellBounds.Bottom-1)); 
     } 
     e.PaintContent(e.ClipBounds); 
    } 
} 

enter image description here

相關問題