1 Replies - 1776 Views - Last Post: 13 December 2011 - 09:13 AM Rate Topic: -----

#1 priyamtheone  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 75
  • Joined: 02-September 08

How to set borderstyle of a datagridview column at runtime (.Net 4.0)?

Posted 08 December 2011 - 09:09 AM

I have a readonly datagridview that is bound to a datasource. It has two columns. Now I want the first column to have no cell borderstyle; and the second one to have 'All' (i.e. all sides of the cell shall have a border) as cell borderstyle. Before binding the datagridview to the datasource, I'm writing something like mentioned below but it's taking no effect. Assume the column in question is named DisplayName.

Dim newStyle As New DataGridViewAdvancedBorderStyle()
With newStyle
.Top = DataGridViewAdvancedCellBorderStyle.Single
.Left = DataGridViewAdvancedCellBorderStyle.Single
.Bottom = DataGridViewAdvancedCellBorderStyle.Single
.Right = DataGridViewAdvancedCellBorderStyle.Single
End With

DisplayName.CellTemplate.AdjustCellBorderStyle(newStyle, newStyle, True, True, True, True)



Please rectify or suggest a better way. Regards.

Is This A Good Question/Topic? 0
  • +

Replies To: How to set borderstyle of a datagridview column at runtime (.Net 4.0)?

#2 priyamtheone  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 75
  • Joined: 02-September 08

Re: How to set borderstyle of a datagridview column at runtime (.Net 4.0)?

Posted 13 December 2011 - 09:13 AM

Private Sub dgvLegends_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgvLegends.CellPainting
        'Draw custom cell borders.
        'If current column is DisplayName...
        If dgvLegends.Columns("DisplayName").Index = e.ColumnIndex AndAlso e.RowIndex >= 0 Then
                Dim Brush As New SolidBrush(dgvLegends.ColumnHeadersDefaultCellStyle.BackColor)
                e.Graphics.FillRectangle(Brush, e.CellBounds)
                Brush.Dispose()
                e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentBackground)

                ControlPaint.DrawBorder(e.Graphics, e.CellBounds, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid)

            e.Handled = True
        End If
    End Sub

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1