MrPatterns
MrPatterns

Reputation: 4434

How do I activate/select/give focus to a listbox control in vb6?

So let's say I have a listbox called lstFruits, that contains some words in there. Now let's say I have a string strString which contains "lstFruits" (the name of the listbox).

So strString = "lstFruits".

How do I go from the string to activating and giving focus to the lstFruit listbox? I know there's lstFruits.Select or lstFruits.Focus....but I want to be able to activate the listbox from the string strString....Eventually I'd like strString to contain the name of 1 listbox out of many possible ones, and give focus to the listbox spelled out by strString.

Upvotes: 2

Views: 1584

Answers (2)

MarkJ
MarkJ

Reputation: 30398

The VB6 version is

Me.Controls("lstFruits").SetFocus

Documentation: SetFocus, Controls collection

Upvotes: 1

Kamil
Kamil

Reputation: 13931

Im not sure if this will work in VB6, i tested it on VB.NET

Me.Controls("lstFruits").Focus()

Where "Me" represents your form or other "container" control which contains listbox.

Upvotes: 2

Related Questions