0

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

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;
    }
4

0 回答 0