Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Different C1TrueDBGrid Question

Status
Not open for further replies.

dolfo35

Programmer
Jan 26, 2001
28
US
Now that I know some of you use this control I'm hoping that someone has the answer to this question.

In the samples there is a project called "Hyperlink". I'm using it to learn how to add a hyperlink column into a much larger project. The only problem is that it has an error in it. If you run the project and point directly to the hyperlink column it works fine. The error happens in the mousemove event when you point to a column that only has a string in it.

Code:
Dim link As Hyperlink = CType(Me.C1TrueDBGrid1(row, col), Hyperlink)

This is the line of code that causes the error as far as I can tell, since it is the one highlighted when the program stops.

Thanks for any help you can provide.

Rudy
 
Could you please post the exact error description please?

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Ruffnekk,

Thanks for your reply. I guess that would have helped. I'll include more detail next time. As for this time, I got an email yesterday from John Ayers of ComponentOne. If you have the Hyperlink example and have this same problem, replace the MouseMove event of the C1TrueDBGrid with this:

Code:
      ' change the cursor over a link
    Private Sub C1TrueDBGrid1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles C1TrueDBGrid1.MouseMove
        Dim cursor As Cursor = Cursors.Default
         
        Dim row, col As Integer

        If Me.C1TrueDBGrid1.CellContaining(e.X, e.Y, row, col) Then

            ' make sure we're on the hyperlink column
[b]            ' this is the line that is added to the sample
            ' to make it work correctly
            If Me.C1TrueDBGrid1.Columns(col).DataField = "Link" Then[/b]

                Dim link As Hyperlink = CType(Me.C1TrueDBGrid1(row, col), Hyperlink)
                If Not (link Is Nothing) Then
                    Dim g As Graphics = Me.C1TrueDBGrid1.CreateGraphics()
                    Try
                        Dim r As Rectangle = _
                        Me.C1TrueDBGrid1.Splits(0).GetCellBounds(row, col)
                        Dim width As Integer = _
                        CInt(g.MeasureString(link.ToString(), Me.C1TrueDBGrid1.Font).Width)
                        If e.X - r.Left <= width Then
                            cursor = Cursors.Hand
                        End If
                    Finally
                        g.Dispose()
                    End Try
                End If
            [b]End If[/b]

        End If

        Me.C1TrueDBGrid1.Cursor = cursor

    End Sub

Hope that helps someone else. I was able to use what I learned from this sample, apply it to my project and it is now in production.

Have a great day!
Rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top