Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
th line of codeI have a DataGridView constructed of selected data from my database. Because of size constraints I have truncated 2 of the columns. When I click on one of the cells in the columns a textbox opens and is supposed to display the complete text in that field. When I do click on the cell the textbox opens, but the text is displayed across the top of the box and nothing in the body. If I press enter or the spacebar the text then appears in the body of the box.
How can I have the text appear in the box when it opens?
I have attached the cell-click subroutine and the textbox routine.

I have also tried the ToolTip tool and it works, but there are two problems. I would like to be able to control the window appearance similar to the CellClick code(the window size, and color, and the font type and size) and have it stay active until released with a close button.
(Basic code attached)

What I have tried:

CellClick Code

VB
Private Sub grdViewMovies_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles grdViewMovies.CellClick
        
        Dim value As Object = grdViewMovies.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
        Dim colNumb As String = grdViewMovies.CurrentCell.ColumnIndex.ToString

        'Make sure only information in columns 1 or 2 is displayed.

        If colNumb = 1 or colNumb = 2 Then

            'If there is no data in the cell

            If IsDBNull(value) Then
                MessageBox.Show("NO DATA IN THIS CELL", " NOTHING HERE", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf colNumb = "0" Then
                Form1.again = False
                Exit Sub
            Else         'Open sayitForm and display the text that is in the cell
                displayText = CType(value, String)
                Using sayitForm As New INFORMATION
                    sayitForm.Text = displayText
                    sayitForm.ShowDialog(Me)
                End Using
            End If
        End If
    End Sub

    Private Sub closeBtn_Click(sender As Object, e As EventArgs) Handles closeBtn.Click

    End Sub
End ClassPublic Class INFORMATION

    Private Sub txtSayit_TextChanged(sender As Object, e As EventArgs) Handles txtSayit.TextChanged
        txtSayit.Text = SQLForm.displayText
    End Sub

End Class



ToolTip Code

Private Sub grdViewMovies_CellMouseEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdViewMovies.CellMouseEnter

        Dim myRow As Integer = e.RowIndex
        Dim myCol As Integer = e.ColumnIndex

        If myCol = 1 Or myCol = 2 And myRow > 0 Then
            Me.grdViewMovies.Rows(myRow).Cells(myCol).ToolTipText = Me.grdViewMovies.Rows(myRow).Cells(myCol).Value
        End If

    End Sub
Posted
Updated 3-Jan-18 6:31am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900