Home All Groups Group Topic Archive Search About
Author
7 Oct 2005 2:34 PM
Arpan
Clicking different CommandButtons on a VB6 Form adds the Captions of
the CommandButtons as items in a ListBox one below the other. For e.g.
when a user clicks the CommandButton "5", "5" gets added as the 1st
item in the ListBox. Next when the user clicks the CommandButton "2",
"2" gets added as the 2nd item in the ListBox below "5" so on & so
forth. I want that when an item gets added to the ListBox, that item
should get highlighted/selected. For e.g. when "5" gets added to the
ListBox, "5" should be highlighted/selected. Next when "2" gets added
to the ListBox (below "5"), "2" should be highlighted/selected. How do
I do this?

Thanks,

Arpan

Author
7 Oct 2005 2:53 PM
Bob Butler
"Arpan" <arpan***@hotmail.com> wrote in message
news:1128695676.999279.242310@g14g2000cwa.googlegroups.com
> Clicking different CommandButtons on a VB6 Form adds the Captions of
> the CommandButtons as items in a ListBox one below the other. For e.g.
> when a user clicks the CommandButton "5", "5" gets added as the 1st
> item in the ListBox. Next when the user clicks the CommandButton "2",
> "2" gets added as the 2nd item in the ListBox below "5" so on & so
> forth. I want that when an item gets added to the ListBox, that item
> should get highlighted/selected. For e.g. when "5" gets added to the
> ListBox, "5" should be highlighted/selected. Next when "2" gets added
> to the ListBox (below "5"), "2" should be highlighted/selected. How do
> I do this?

list1.additem command1.caption
list1.selected(list1.newindex)=True

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
7 Oct 2005 3:08 PM
Arpan
Thanks Bob.

Regards,

Arpan
Author
7 Oct 2005 3:40 PM
Phill. W
"Arpan" <arpan***@hotmail.com> wrote in message
news:1128695676.999279.242310@g14g2000cwa.googlegroups.com...
> For e.g. when "5" gets added to the ListBox, "5" should be
> highlighted/selected. Next when "2" gets added to the ListBox
> (below "5"), "2" should be highlighted/selected.
> How do I do this?

' List1.AddItem( "2" )
List1.ListIndex = List1.NewIndex

HTH,
    Phill  W.
Author
7 Oct 2005 4:00 PM
Bob Butler
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:di64bq$aji$1@yarrow.open.ac.uk
> "Arpan" <arpan***@hotmail.com> wrote in message
> news:1128695676.999279.242310@g14g2000cwa.googlegroups.com...
>> For e.g. when "5" gets added to the ListBox, "5" should be
>> highlighted/selected. Next when "2" gets added to the ListBox
>> (below "5"), "2" should be highlighted/selected.
>> How do I do this?
>
> ' List1.AddItem( "2" )
> List1.ListIndex = List1.NewIndex

Yep, I stopped reading at "highlighted" and missed "selected"

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
7 Oct 2005 4:25 PM
Arpan
Bob, the code you provided also selects/highlights the just added item
to the ListBox; so what difference does it make if I use your code or
Phill's code as both the codes do the needful.

Thanks once again & thanks to Phill as well.

Regards,

Arpan
Author
7 Oct 2005 5:00 PM
Bob Butler
"Arpan" <arpan***@hotmail.com> wrote in message
news:1128702322.932624.15400@o13g2000cwo.googlegroups.com
> Bob, the code you provided also selects/highlights the just added item
> to the ListBox; so what difference does it make if I use your code or
> Phill's code as both the codes do the needful.
>
> Thanks once again & thanks to Phill as well

Set the .MultiSelect option of the listbox to allow multiple selections and
you'll see a difference.  Mine selects each item; Phil's sets the currently
selected item to be the newest item.  Both are useful but it depends on what
you want.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
7 Oct 2005 6:45 PM
Arpan
I got the point, Bob. Thank you very much.

Regards,

Arpan