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:
- Add 1 ListBox, then 1 TextBox (property Visible = False) to the Form.
- 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 - 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 - Type This code in event TextBox1_LostFocus :
TextBox1.Visible = False
- 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
0 comments:
Post a Comment