Home » » ListBox can be in Edit

ListBox can be in Edit


In order for the items contained in the ListBox can be edited, it would require a special way by combining it with the TextBox. Here's how:

    1. Add 1 ListBox, then 1 TextBox (property Visible = False) to the Form.
    1. Type this code in the event ListBox1_MouseDoubleClick:
      Dim i As Integer = ListBox1.SelectedIndex
      If i < 0 Then Exit Sub

      With TextBox1
        .Top = ListBox1.GetItemRectangle(i).Top + ListBox1.Top
        .Left = ListBox1.GetItemRectangle(i).Left + ListBox1.Left

        .Text = ListBox1.Items(i)
        .Visible = True
        .Focus()
      End With

    2. Type This code in event TextBox1_KeyPress :
      If e.KeyChar = Chr(Keys.Enter) Then
        ListBox1.Items(ListBox1.SelectedIndex) = TextBox1.Text
        TextBox1.Visible = False
      ElseIf e.KeyChar = Chr(Keys.Escape) Then
        TextBox1.Visible = False
      End If

    3. Type This code in event TextBox1_LostFocus :
      TextBox1.Visible = False

    4. For the experiment, you can fill out the items by typing in this code in event Form1_Load :
      Dim i As Integer
      For i = 1 To 100
        ListBox1.Items.Add("Item ke " & i)
      Next
    Run the application, and then double-click the item to be edited.
    Jika Anda menyukai Artikel di blog ini, Silahkan klik disini untuk berlangganan gratis via email, dengan begitu Anda akan mendapat kiriman artikel setiap ada artikel yang terbit di Creating Website

    0 comments:

    Post a Comment

     
    Support : Creating Website | Johny Template | Mas Template
    Copyright © 2011. Sanjaya Catur Blogging - All Rights Reserved
    Template Modify by Creating Website
    Proudly powered by Blogger