As of now I can place a textbox into a listview and retrieve the value. However, once I start to move the vertical scroll bar the textbox does not stay in the desired subitem space. I had seen an example with datagridview, which I tried to use with listview, but the same thing keeps happening when I use the scrollbar.
here is the code I am using:
Private Sub ListView1_Click(sender As Object, e As EventArgs) Handles ListView1.MouseClick
If Not txb Is Nothing Then
RemoveHandler txb.Leave, AddressOf txb_Leave
ListView1.Controls.Remove(txb)
txb.Hide()
txb = Nothing
End If
txb = New TextBox()
txb.Width = 217
txb.Text = Me.ListView1.SelectedItems(0).SubItems(1).Text
' txb.Location = New Point(ListView1.SelectedItems.Item(0).SubItems.Item(1).Bounds.X, ListView1.SelectedItems.Item(0).SubItems.Item(1).Bounds.Y - 1)
txb.Tag = Me.ListView1.SelectedItems(0)
AddHandler txb.Leave, AddressOf txb_Leave
ListView1.Controls.Add(txb)
' txb.Focus()
'this portion of code sets the textbox control to active allowing the cursor to be placed in it without the mouse hover over.
Me.ActiveControl = txb
ListView1_Rect()
End Sub
Private Sub txb_Leave(sender As Object, e As EventArgs) Handles txb.Leave
Dim item As ListViewItem
item = CType(txb.Tag, ListViewItem)
item.SubItems(1).Text = txb.Text
End Sub
Private Sub ListView1_Rect()
Dim x As Integer = 0
Dim y As Integer = 0
Dim Width As Integer = 0
Dim height As Integer = 0
' GET THE ACTIVE CELL'S DIMENSIONS TO BIND THE textbox WITH IT.
Dim rect As Rectangle
rect = ListView1.GetItemRect(1, 2)
x = rect.X + ListView1.Left
y = rect.Y + ListView1.Top
Width = rect.Width
height = rect.Height
With txb
.SetBounds(x, y, Width, height)
.Visible = True
.Focus()
End With
End Sub
What I have tried:
I have tried the listview1.getitemtrect function in hopes to create a rectangle to bind the textbox too. However, it is not binding to it. I have also tried to draw a rectangle in the subitem space for a textbox. This created a continuous flickering effect, but the textbox did move with the scrollbar.