DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    65

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

    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.

    Code:
    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.

  2. #2
    Join Date
    Mar 2009
    Posts
    65

    Thumbs up

    Code:
    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

Similar Threads

  1. Replies: 4
    Last Post: 04-03-2009, 11:23 AM
  2. Replies: 0
    Last Post: 02-12-2003, 04:20 AM
  3. .NET Framework Poll
    By Ovidiu Platon in forum .NET
    Replies: 0
    Last Post: 08-26-2002, 09:03 AM
  4. C# & .NET
    By Vikas Garg in forum Careers
    Replies: 18
    Last Post: 07-13-2002, 11:58 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links