小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Windows Forms DataGridView 中合并單元格(轉(zhuǎn))

 zhanghuan 2007-09-29
Windows Forms DataGridView 沒有提供合并單元格的功能,要實現(xiàn)合并單元格的功能就要在CellPainting事件中使用Graphics.DrawLine和 Graphics.DrawString 自己來“畫”。

下面的代碼可以對DataGridView第1列內(nèi)容相同的單元格進行合并:
        private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            
// 對第1列相同單元格進行合并
            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {
                
using
                    (
                    Brush gridBrush 
= new SolidBrush(this.dataGridView1.GridColor),
                    backColorBrush 
= new SolidBrush(e.CellStyle.BackColor)
                    )
                {
                    
using (Pen gridLinePen = new Pen(gridBrush))
                    {
                        
// 清除單元格
                        e.Graphics.FillRectangle(backColorBrush, e.CellBounds);

                        
// 畫 Grid 邊線(僅畫單元格的底邊線和右邊線)
                        
//   如果下一行和當前行的數(shù)據(jù)不同,則在當前的單元格畫一條底邊線
                        if (e.RowIndex < dataGridView1.Rows.Count - 1 &&
                        dataGridView1.Rows[e.RowIndex 
+ 1].Cells[e.ColumnIndex].Value.ToString() != 
                        e.Value.ToString())
                            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
                            e.CellBounds.Bottom 
- 1, e.CellBounds.Right - 1,
                            e.CellBounds.Bottom 
- 1);
                        
// 畫右邊線
                        e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
                            e.CellBounds.Top, e.CellBounds.Right 
- 1,
                            e.CellBounds.Bottom);

                        
// 畫(填寫)單元格內(nèi)容,相同的內(nèi)容的單元格只填寫第一個
                        if (e.Value != null)
                        {
                            
if (e.RowIndex > 0 &&
                            dataGridView1.Rows[e.RowIndex 
- 1].Cells[e.ColumnIndex].Value.ToString() == 
                            e.Value.ToString())
                            { }
                            
else
                            {
                                e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                                    Brushes.Black, e.CellBounds.X 
+ 2,
                                    e.CellBounds.Y 
+ 5, StringFormat.GenericDefault);
                            }
                        }
                        e.Handled 
= true;
                    }
                }
            }
        }

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多