我想只删除一列的边框线

时间:2013-10-24 12:37:27

标签: datagridview

我想只删除一列的边框线。所以我使用下面的代码。但它适用于所有列。请告诉我,如何仅为一列删除边界线。

private void dgvInvoiceDetails_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {       
          //  dgvInvoiceDetails.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; 
          //  dgvInvoiceDetails.CellBorderStyle = DataGridViewCellBorderStyle.None;

            if (e.RowIndex == -1 && e.ColumnIndex > -1)
            {
                if (dgvInvoiceDetails.Columns[1].Name == "Account1234")
                {
                    e.Handled = true;
                    using (Brush b = new SolidBrush(dgvInvoiceDetails.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);
                }
            }

        //string Name = dgvInvoiceDetails.Columns[1].Name;
        //if (e.RowIndex == -1 && e.ColumnIndex == dgvInvoiceDetails.Columns[Name].Index)
        //    e.AdvancedBorderStyle.Right = DataGridViewAdvancedCellBorderStyle.None;
    }

0 个答案:

没有答案