Results 1 to 2 of 2

Thread: [solved] listview subitem location

Threaded View

  1. #1

    Thread Starter
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552

    [solved] listview subitem location

    i'm creating a listview that if double clicked, it gets the location and temporarily displays a textbox. it works fine with the first column of a listviews sub item but none to the other sub items. what did i miss? this is my code...
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.       Dim cn As New SqlConnection()
    3.       cn.ConnectionString = "integrated security=true;initial catalog=northwind"
    4.       cn.Open()
    5.  
    6.       Dim cmdtext As String = "select * from categories"
    7.       Dim cm As New SqlCommand(cmdtext, cn)
    8.       Dim dr As SqlDataReader = cm.ExecuteReader
    9.  
    10.       Dim i As Integer = 0
    11.       While dr.Read
    12.          ListView1.Items.Add(dr(0))
    13.          ListView1.Items(i).SubItems.Add(dr(1))
    14.          ListView1.Items(i).SubItems.Add(dr(2))
    15.          i += 1
    16.       End While
    17.  
    18.       TextBox1.Hide()
    19.    End Sub
    20.  
    21.    Dim li As ListViewItem
    22.    Dim x As Integer = 0
    23.    Dim subitemtext As String
    24.    Dim subitemselected As Integer
    25.  
    26.    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    27.       If e.KeyCode = Keys.Enter Then
    28.          li.SubItems(subitemselected).Text = TextBox1.Text
    29.          TextBox1.Hide()
    30.       End If
    31.       If e.KeyCode = Keys.Escape Then
    32.          TextBox1.Hide()
    33.       End If
    34.    End Sub
    35.  
    36.    Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
    37.       li.SubItems(subitemselected).Text = TextBox1.Text
    38.       TextBox1.Hide()
    39.    End Sub
    40.  
    41.    Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
    42.       Dim this As ListView = sender
    43.       Dim nstart As Integer = x
    44.       Dim spos As Integer = 0
    45.       Dim epos = this.Columns(0).Width
    46.       Dim i As Integer
    47.       For i = 0 To this.Columns.Count - 1
    48.          If nstart > spos And nstart < epos Then
    49.             subitemselected = i
    50.             Exit For
    51.          End If
    52.          spos = epos
    53.          epos += this.Columns(i).Width
    54.       Next
    55.       subitemtext = li.SubItems(subitemselected).Text
    56.       TextBox1.Size = New Size(epos - spos, li.Bounds.Bottom - li.Bounds.Top)
    57.       TextBox1.Location = New Point(spos + this.Location.X + 2, li.Bounds.Y + this.Location.Y)
    58.       TextBox1.Show()
    59.       TextBox1.Text = subitemtext
    60.       TextBox1.SelectAll()
    61.       TextBox1.Focus()
    62.    End Sub
    63.  
    64.    Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
    65.       li = sender.getitemat(e.X, e.Y)
    66.       x = e.X
    67.    End Sub
    thanx...
    Last edited by brown monkey; Jun 22nd, 2004 at 01:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width