Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems using List Boxes

Status
Not open for further replies.

mauricebaker

Programmer
Jan 2, 2005
3
0
0
GB
When using LIST BOXES I have experienced three unwanted problems:-

1. Typing the first letter of a List member in the List box causes the selection of the list item.
2. The “Arrow” keys select a list item.
3. When the List Box is Hidden after selection and then again made Visible for re-use,the previously selected List item is highlighted in a blue background.

I am a new to Visual Basic 6 and find that the textbooks that I have do not deal with these details.

I should be most grateful if anyone could tell me how to avoid these problems.

Are there further properties such as “name.ListIndex” which are not dealt with in any of my textbooks and which are related to List Boxes?

 
As Microsoft says "... this behavior is by design ...".

You can deselect an item in a listbox with
Code:
List1.ListIndex = -1

You can disable searching on a keypress with
Code:
Private Sub List1_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
End Sub

and you can disable list navigation (arrow keys) with

Code:
Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
    KeyCode = 0
End Sub
 
This is for two list boxes, list1 and 2.

If user clicks item in #1, this will add it to #2 and remove it from #1:

'-- ADD THE ITEM TO THE SECOND LIST
List2.AddItem ("" & List1.Text & "")

'-- REMOVE THE ITEM FROM THE FIRST LIST
List1.RemoveItem ("" & List1.ListIndex & "")

Hope this might help.

Shannan
 
Shannan, FYI:

Code:
List2.AddItem ("" & List1.Text & "")
is eqivalent to
Code:
List2.AddItem List1.Text
in terms of the result. Since List1.Text is already a string, it's not necessary to attempt to enclose its value in literal quotes, as yours does. The literal quotes are superfluous, and the parens are actually causing the string to the additem method to be passed by value instead of by reference, rather than being part of the syntax to enclose the argument.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top