Home All Groups Group Topic Archive Search About

ListBox - Limit Selection Rectangle Width

Author
4 Jul 2009 6:12 PM
David
I have a tabbed listbox. Is there anyway to limit the item selection
rectangle (highlight) to the 1st column instead of having it go across the
entire listbox?

Author
4 Jul 2009 7:13 PM
mayayana
A tabbed listbox? If that's VB.Net then you're
in the wrong group. If it's VB then I've never
heard of a tabbed listbox, but you can do what
you want in a listbox.
See this code sample:
www.jsware.net/jsware/vbcode.php5#lbox

  If you look at the DrawItem sub in the
UserControl you'll see that it paints the
background and then the text according
to selected colors. It also deals with whether
an item is selected. The drawing/painting
takes place in a defined rectangle (Rect).
To achieve what you want you could use
the same colors for selection as for non-
selection, then when an item is selected,
paint a box on the left with your selection
color and inset the rect for the text painting.
The result would be that a selected item
would show as a normal item marked by
a colored square on the left side. If you
really had to highlight the first character that
should be doable, too, but it'd be more
involved. You'd have to paint the background,
then paint your selection rect on the left-side,
then you'd have to call DrawText twice to do
first the first letter and then the rest of the
item string. There might also be a tricky part
in figuring out exactly how wide that first
character will be. See the AddScrollHz sub in
the same UserControl for a demo of how to
measure the text width.

Show quoteHide quote
> I have a tabbed listbox. Is there anyway to limit the item selection
> rectangle (highlight) to the 1st column instead of having it go across the
> entire listbox?
>
>
Are all your drivers up to date? click for free checkup

Author
5 Jul 2009 6:16 PM
David
mayayana

Using  VB5 / 6.

--------------

This is how you make a Tabbed Listbox

    'SetUp ListBox Tab Stops
    ListBoxTabs(0) = 16    '16/4 = 4 characters
    ListBoxTabs(1) = 32    '32/4 = 8 characters
    ListBoxTabs(2) = 64    '64/4 = 16 characters

    lngDummy = SendMessage(objList.hwnd, LB_SETTABSTOPS, UBound(ListBoxTabs)
+ 1, ListBoxTabs(0))   '4

-----------------

Thanks for the link.  Will take a look see.


Show quoteHide quote
"mayayana" <mayaXXy***@rcXXn.com> wrote in message
news:OvpJUvN$JHA.4984@TK2MSFTNGP05.phx.gbl...
>A tabbed listbox? If that's VB.Net then you're
> in the wrong group. If it's VB then I've never
> heard of a tabbed listbox, but you can do what
> you want in a listbox.
> See this code sample:
> www.jsware.net/jsware/vbcode.php5#lbox
>
>  If you look at the DrawItem sub in the
> UserControl you'll see that it paints the
> background and then the text according
> to selected colors. It also deals with whether
> an item is selected. The drawing/painting
> takes place in a defined rectangle (Rect).
> To achieve what you want you could use
> the same colors for selection as for non-
> selection, then when an item is selected,
> paint a box on the left with your selection
> color and inset the rect for the text painting.
> The result would be that a selected item
> would show as a normal item marked by
> a colored square on the left side. If you
> really had to highlight the first character that
> should be doable, too, but it'd be more
> involved. You'd have to paint the background,
> then paint your selection rect on the left-side,
> then you'd have to call DrawText twice to do
> first the first letter and then the rest of the
> item string. There might also be a tricky part
> in figuring out exactly how wide that first
> character will be. See the AddScrollHz sub in
> the same UserControl for a demo of how to
> measure the text width.
>
>> I have a tabbed listbox. Is there anyway to limit the item selection
>> rectangle (highlight) to the 1st column instead of having it go across
>> the
>> entire listbox?
>>
>>
>
>
Author
5 Jul 2009 6:30 PM
mayayana
> This is how you make a Tabbed Listbox
>
>     'SetUp ListBox Tab Stops
>     ListBoxTabs(0) = 16    '16/4 = 4 characters
>     ListBoxTabs(1) = 32    '32/4 = 8 characters
>     ListBoxTabs(2) = 64    '64/4 = 16 characters
>
>     lngDummy = SendMessage(objList.hwnd, LB_SETTABSTOPS,
UBound(ListBoxTabs)
> + 1, ListBoxTabs(0))   '4
>

   I've never seen that before. I looked up
LB_SETTABSTOPS but I'm not sure that I
understand it. Would the result of your code
be that once somebody tabs into your listbox
their next tab would take them to item 4,
then to item 8, then item 16, then out of the
listbox to the next control?

  What's the point of something like that,
that would improve over tabbing between
controls and using arrow keys in the listbox?
Is it to allow quick access to items that are
a ways down the list in a listbox that's accessed
frequently?
Author
5 Jul 2009 7:46 PM
Larry Serflaten
"mayayana" <mayaXXy***@rcXXn.com> wrote
> > This is how you make a Tabbed Listbox

>    I've never seen that before.

Where you been?  That's a pretty old trick.  This guy was using that in VB2:
http://vbnet.mvps.org/code/listapi/listboxtabs.htm

<Shrug>
LFS
Author
5 Jul 2009 9:37 PM
mayayana
> >    I've never seen that before.
>
> Where you been?  That's a pretty old trick.  This guy was using that in
VB2:
> http://vbnet.mvps.org/code/listapi/listboxtabs.htm
>
> <Shrug>

   So you're going to make me guess
because I'm so stupid? I hope you never
decide to become a nurse or social worker.
You just don't have the "bedside manner". :)

  If I read Randy's page correctly it's setting
the width of a tab character. So that's
a way to simulate columns in a listbox?
That seems very clunky and of limited
usefulness, but it makes more sense to me
than trapping the tab key in the listbox.

  When I'd first read David's post I thought
he was talking about some kind of tabstrip/
listbox combo control. That's why I wondered
if he was using .Net.
    Odd, when one thinks
about it, that the word "tab" has been used so
ambiguously. There are 3 possible meanings
there, all entirely different. And it took me
3 guesses to figure out which tab we were
talking about here!
Author
6 Jul 2009 1:02 AM
Larry Serflaten
"mayayana" <mayaXXy***@rcXXn.com> wrote
> > >    I've never seen that before.
> >
> > Where you been?  That's a pretty old trick.  This guy was using that in
> VB2:
> > http://vbnet.mvps.org/code/listapi/listboxtabs.htm
> >
> > <Shrug>
>
>    So you're going to make me guess
> because I'm so stupid?

Guess what?  I wasn't addressing any other thing you
posted, other than how common that idea was.

> I hope you never decide to become a nurse

There is a little too much of that going around already! <g>

>   If I read Randy's page correctly it's setting
> the width of a tab character.

Try it and see.  There is a big difference between tab width
and tab stop.  If it set the tab width, lines like:

"cat" & vbTab & "mammal"
"elephant" & vbTab & "mammal"

Would not be in columns becase the first words are different
sizes.  Using tab stops appropreatly would leave the "mammal"
column all line up from item to item....

LFS
Author
6 Jul 2009 1:55 AM
Nobody
"David" <dw85745***@earthlink.net> wrote in message
news:uJGrOMN$JHA.4984@TK2MSFTNGP05.phx.gbl...
>I have a tabbed listbox. Is there anyway to limit the item selection
>rectangle (highlight) to the 1st column instead of having it go across the
>entire listbox?

Why not use ListView control? It has that feature.
Author
6 Jul 2009 11:45 AM
David
Hi Nobody:

Was trying to replicate MS IDE Control Property Window.

Spy++ indicates they are using a Listbox.

If can't resolve RECT area (select highlight) will go with MSFlexgrid or
ListView, but for now like to give it a shot.

Show quoteHide quote
"Nobody" <nob***@nobody.com> wrote in message
news:eznydzd$JHA.4692@TK2MSFTNGP02.phx.gbl...
> "David" <dw85745***@earthlink.net> wrote in message
> news:uJGrOMN$JHA.4984@TK2MSFTNGP05.phx.gbl...
>>I have a tabbed listbox. Is there anyway to limit the item selection
>>rectangle (highlight) to the 1st column instead of having it go across the
>>entire listbox?
>
> Why not use ListView control? It has that feature.
>
>
Author
7 Jul 2009 9:29 PM
Karl E. Peterson
David wrote:
> Was trying to replicate MS IDE Control Property Window.
>
> Spy++ indicates they are using a Listbox.

Huh!  Never noticed that before.  Definitely not native.  It's probably owner-drawn.
Example:

vbAccelerator - Owner Draw Combo and List Boxes Version 2.1
http://www.vbaccelerator.com/home/vb/Code/Controls/Combo_and_List_Boxes/Owner_Draw_Combo_and_List_Box/article.asp
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
8 Jul 2009 2:46 AM
David
Thanks Karl

Looks like might be more trouble than its worth since Flexgrid should be
adaptable fairly easily for what I want to do.

Consider thread closed

David

Show quoteHide quote
"Karl E. Peterson" <k***@exmvps.org> wrote in message
news:uZyWOo0$JHA.1376@TK2MSFTNGP02.phx.gbl...
> David wrote:
>> Was trying to replicate MS IDE Control Property Window.
>>
>> Spy++ indicates they are using a Listbox.
>
> Huh!  Never noticed that before.  Definitely not native.  It's probably
> owner-drawn. Example:
>
> vbAccelerator - Owner Draw Combo and List Boxes Version 2.1
> http://www.vbaccelerator.com/home/vb/Code/Controls/Combo_and_List_Boxes/Owner_Draw_Combo_and_List_Box/article.asp
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>

Bookmark and Share