datagridview offsets to cell off screen?

How do I find the x/y offsets to a cell that is off screen?
PizpotAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PizpotAuthor Commented:
I mean scrolled out of view, not off screen.
0
brianpsmith81Commented:
Just a single cell is off the screen? I think I need more information.  Could you perhaps post the code that is giving you the issue?  Thanks
0
PizpotAuthor Commented:
If a user clicks on a cell, I want to be able to draw a line to another cell whether it is scrolled and not visible, or not. Here is a link to my last question/answer, which handles the case where one cell is not visible. But once that cell is not visible, it gets drawn to 0,0.  

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23127884.html

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

PizpotAuthor Commented:
edit last post:

If a user clicks on a cell, I want to be able to draw a line to another cell whether it is scrolled and not visible, or not. Here is a link to my last question/answer, which handles the case where both cells are visible.

If you try it when the 2nd cell is not visible, the line it to 0,0.


http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23127884.html
0
PizpotAuthor Commented:
I think I am just going to estimate the pixel offsets to off screen cells. Plus or minus a fex pixels in the y axis will not be noticable.
0
vb_jonasCommented:
Hi Pizpot! I had some fun creating a clipping function aswell. Heres the new improved DataGridView1_Paint :
    Private Sub DataGridView1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGridView1.Paint
        Dim c1, c2, r1, r2 As Int16
 
        ' from cell 1
        c1 = 1 : r1 = 15
 
        ' to cell 2
        c2 = 2 : r2 = 30
 
        If DataGridView1.Rows.Count >= r2 - 1 Then
 
            Dim p As Pen = New Pen(Color.Red)
            Dim rectCell1 As Rectangle, rectCell2 As Rectangle
 
            rectCell1 = DataGridView1.GetCellDisplayRectangle(c1, r1, False)
            rectCell2 = DataGridView1.GetCellDisplayRectangle(c2, r2, False)
 
            Dim r As Int16
            Dim c As Int16
            Dim ro As Integer = 0
            Dim co As Integer = 0
 
            ' Calculate the distance between cell 1 and cell 2
            For r = r1 To r2 - 1
                ro = ro + DataGridView1.Rows(r).Height
            Next
            For c = c1 To c2 - 1
                co = co + DataGridView1.Columns(c).Width
            Next
 
            Dim lineTo As Point
            Dim lineFrom As Point
 
            ' Calculate the coordinates of the non-visible cell
            If (rectCell2.X = 0 And rectCell2.Y = 0) Then
                ' Cell 2 is invisible
 
                If (rectCell1.X = 0 And rectCell1.Y = 0) Then
                    ' Both cells are invisible - no line
                    Exit Sub
                End If
                rectCell2.X = rectCell1.X + co
                rectCell2.Y = rectCell1.Y + ro
                rectCell2.Height = DataGridView1.Rows(r2).Height
                rectCell2.Width = DataGridView1.Columns(c2).Width
            End If
            If (rectCell1.X = 0 And rectCell1.Y = 0) Then
 
                ' Cell 1 is invisible
                rectCell1.X = rectCell2.X - co
                rectCell1.Y = rectCell2.Y - ro
                rectCell1.Height = DataGridView1.Rows(r1).Height
                rectCell1.Width = DataGridView1.Columns(c1).Width
            End If
 
            ' From cell 1 left edge
            lineFrom.X = rectCell1.X
            lineFrom.Y = rectCell1.Y + rectCell1.Height / 2
 
            ' To cell 2 right edge
            lineTo.X = rectCell2.X + rectCell2.Width
            lineTo.Y = rectCell2.Y + rectCell2.Height / 2
 
            Dim g As Graphics
            g = Me.DataGridView1.CreateGraphics
 
            ' Sett clipping region to be inside the griddata, exclude headers
            g.Clip = New Region(New Rectangle(DataGridView1.RowHeadersWidth, DataGridView1.ColumnHeadersHeight, g.ClipBounds.Width - DataGridView1.RowHeadersWidth, g.ClipBounds.Height - DataGridView1.ColumnHeadersHeight))
 
            ' Draw the line with clipping
            g.DrawLine(p, lineFrom, lineTo)
            g.Dispose()
 
        End If
 
 
    End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PizpotAuthor Commented:
interesting... :-)
0
vb_jonasCommented:
Yes, isn't it? :-) Did it work as you expected?
0
PizpotAuthor Commented:
Yes it did, thanks very much. I will even use it if both cells are not visible because that can happen as you scroll around. :-)
0
PizpotAuthor Commented:
Yes it did, thanks very much. I will even use it if both cells are not visible because that can happen as you scroll around. :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.