?
Solved

Vertical line in datagridview

Posted on 2009-04-04
4
Medium Priority
?
615 Views
Last Modified: 2012-05-06
I got the horizontal line working and tried the same technique to draw a different color vertical line between two columns but it doesn't work.

Try
            Dim g As Graphics = DataGridView1.CreateGraphics()
            Dim p As Pen = New Pen(Color.Black)
            Dim rect1 As Rectangle, rect2 As Rectangle
            rect1 = DataGridView1.GetCellDisplayRectangle(16, 0, True)
            rect2 = DataGridView1.GetCellDisplayRectangle(16, DataGridView1.Rows.Count - 1, True)
            Dim linefrom As Point, lineto As Point
            linefrom.X = rect1.Left
            linefrom.Y = rect1.Top + 1
            lineto.X = rect2.Left
            lineto.Y = rect2.Bottom + 1
            g.DrawLine(p, linefrom, lineto)
        Catch ex As Exception
            errlog.WriteError("Error in paint lines: " & ex.Message, "PaintLines")
        End Try
0
Comment
Question by:ddepuemd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24077167
It might be easier if you handle the CellPainting event, and check to see if the cell's ColumnIndex is the one that you need, and then you give the illusion that you are drawing a single continuous line...
0
 

Author Comment

by:ddepuemd
ID: 24077347
I'm not sure I understand what you mean.  How could I do that?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 24080420
Example:


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Me.dgv.RowTemplate.Height = Me.dgv.ClientSize.Height / 3
 
        Me.dgv.RowCount = 3
        Me.dgv.ColumnCount = 3
        Me.dgv.RowHeadersVisible = False
        Me.dgv.ColumnHeadersVisible = False
 
        Me.dgv.Columns(0).Width = Me.dgv.ClientSize.Width / 3
        Me.dgv.Columns(1).Width = Me.dgv.Columns(0).Width
        Me.dgv.Columns(2).Width = Me.dgv.Columns(0).Width
 
        Me.dgv.ScrollBars = ScrollBars.None
        Me.dgv.DefaultCellStyle.SelectionBackColor = Me.dgv.DefaultCellStyle.BackColor
        Me.dgv.DefaultCellStyle.SelectionForeColor = Me.dgv.DefaultCellStyle.ForeColor
 
        AddHandler Me.dgv.CellPainting, AddressOf OnCellPainting
 
    End Sub
 
    Private Sub OnCellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs)
 
        If e.ColumnIndex = 1 Then
            Dim x As Integer = e.CellBounds.Right - 3
            Dim y1 As Integer = e.CellBounds.Top
            Dim y2 As Integer = e.CellBounds.Bottom
 
            e.PaintBackground(e.ClipBounds, e.State = DataGridViewElementStates.Selected)
            e.PaintContent(e.ClipBounds)
            e.Graphics.DrawLine(Pens.Red, x, y1, x, y2)
 
            e.Handled = True
 
        End If
 
    End Sub

Open in new window

DataGridView----Vertical-Line.png
0
 

Author Closing Comment

by:ddepuemd
ID: 31566708
thank you
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 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