Solved

dark line at bottom of datagridview cell

Posted on 2009-04-04
8
367 Views
Last Modified: 2012-05-06
Can someone give me the code to make the bottom line of a DGV cell darker than the other borders?
0
Comment
Question by:ddepuemd
  • 4
  • 4
8 Comments
 

Author Comment

by:ddepuemd
ID: 24066656
I've tried this and it doesn't work.  I can see the lines getting painted but then they go away.

    Private Sub PaintLines()
        For rw As Integer = 0 To DataGridView1.Rows.Count - 1
            If Not IsDBNull(DataGridView1.Rows(rw).Cells(16).Value) Then
                If Mid(DataGridView1.Rows(rw).Cells(16).Value, 2, 2) = ".3" Then
                    Try
                        Dim g As Graphics = DataGridView1.CreateGraphics()
                        Dim p As Pen = New Pen(Color.DarkBlue)
                        Dim rect1 As Rectangle, rect2 As Rectangle
                        rect1 = DataGridView1.GetCellDisplayRectangle(0, rw, True)
                        rect2 = DataGridView1.GetCellDisplayRectangle(22, rw, True)
                        Dim linefrom As Point, lineto As Point
                        linefrom.X = rect1.Left
                        linefrom.Y = rect1.Bottom + 1
                        lineto.X = rect2.Right
                        lineto.Y = rect2.Bottom + 1
                        g.DrawLine(p, linefrom, lineto)
                    Catch ex As Exception

                    End Try
                End If
            End If
        Next
    End Sub

Any ideas on how to make it stick?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24067474
But you want that for ALL lines or just the last one ?
0
 

Author Comment

by:ddepuemd
ID: 24067509
only for certain rows in the grid...
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 48

Expert Comment

by:jpaulino
ID: 24067788
Ýou can use AdvancedBorderStyle on the CellPainting event to change the border to double.
This doesn't work properly if you then edit the item.

    Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
 
        If e.ColumnIndex <> -1 AndAlso e.RowIndex <> -1 Then
 
            ' Checks if the value of the column 1 (index 0) is bigger then 2
            If Me.DataGridView1(0, e.RowIndex).Value > 2 Then
                e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.InsetDouble
            End If
 
        End If
 
    End Sub

Open in new window

0
 

Author Comment

by:ddepuemd
ID: 24067993
Thanks for the input, but it doesn't work.  It seems that when I fill the grid (unbound) it doesn't write the to the cell or overwrites it or something.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24068004
Is the grid unbound and what you want to do ?
Couldn't you fill the line with some backcolor ?
 
0
 

Author Comment

by:ddepuemd
ID: 24068077
The strange thing is that I call the function above after I fill the grid and, as I said, the lines appear then disappear.  If I call the function specifically, as from a button click, the lines show up.  How do I get around that?
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24068309
Try this way instead and use your criteria:
    Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
 
        If e.ColumnIndex <> -1 AndAlso e.RowIndex <> -1 Then
 
            ' Checks if the value of the column 1 (index 0) is bigger then 2
            If Me.DataGridView1(0, e.RowIndex).Value > 2 Then
 
                With e.AdvancedBorderStyle
                    .Top = DataGridViewAdvancedCellBorderStyle.Inset
                    .Left = DataGridViewAdvancedCellBorderStyle.Inset
                    .Right = DataGridViewAdvancedCellBorderStyle.Inset
                    .Bottom = DataGridViewAdvancedCellBorderStyle.Single
                End With
            Else
                With e.AdvancedBorderStyle
                    .Top = DataGridViewAdvancedCellBorderStyle.Inset
                    .Left = DataGridViewAdvancedCellBorderStyle.Inset
                    .Right = DataGridViewAdvancedCellBorderStyle.Inset
                    .Bottom = DataGridViewAdvancedCellBorderStyle.Inset
                End With
            End If
 
        End If
 
    End Sub

Open in new window

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
scanning dentists xray (the small ones) 3 53
Advice in Xamarin 21 78
Crystal reports vb.net 2 39
VB: Convert 2 dates to specific format 24 48
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now