Jump to content

Listbox Questions


Arctor
 Share

Recommended Posts

Hi all

I have 2 questions about listboxes.

1st Question

I have read a topic about listboxes and with this hint of Valik I got the vertical scroll in a listbox to work.

Global $WS_VSCROLL = 0x00200000;
Global $WS_HSCROLL = 0x00100000;
$listbox_style = $WS_VSCROLL + $WS_HSCROLL

FileChangeDir(@ScriptDir)
GUICreate("ListTest", 200, 120)
$listbox1 = GuiSetControl ("list", "", 10,10,180,100,$listbox_style)
GUISetControlData($listbox1, "This is the 1st Item of several very long Items|This is the 2nd Item of several very long Items|This is the 3rd Item of several very long Items")
GUISetControlEx($listbox1, 0, 768, "", 400)

While GUIMsg() <> -3

Wend
But with this solution I have always a horizontal scrollbar even if the items do not exceed the width of the listbox.

And I have to declare the scrollwidth in pixels.

Is it possible to add a horizontal scrollbar only in case the items exceed the width of the listbox? Just as it works with the vertical scrollbar.

Often I use Listboxes to fill them with results from a database, not knowing the length of the rows before.

2nd Question

$LBS_EXTENDEDSEL = 0x800

With this value I can do a listbox with multiselects. I can use the shift and ctrl key to select several items. Very good.

But: I have no idea to get the selected data into a string or an array or whatever. The normal way with GuiRead just gives back the last selected.

arctor

Link to comment
Share on other sites

To help with multi-selects, take a look at this

THX a lot, Cyberslug

With that help I understand it now. I made my own script and it works. Tomorrow I will make my first UDF with that. :D

Is there anybody out there who can give me a hint on my first question? Just a hint where I maybe can get more information on that is enough.

arctor

Link to comment
Share on other sites

Regarding the first question:

Here is some code for Visual Basic. We can perform "LB_SETHORIZONTALEXTENT," but we cannot perform "DrawText API function with the DT_CALCRECT flag."

Setting the scrollbar is easy, but there is no way to calculate the width of the text. I had hoped that LB_GETITEMRECT would work, but the info it returns is not what we need :D

The best you can do, as far as I know, would be to estimate the pixel width based on the font size and number of characters in the string.....

Maybe determine the width of the widest (X) and narrowest (l) characters in the font and use that information to estimate the width of an n-letter word in that font.....

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

THX. I see the problems now.

I also searched msdn and google and I think it's really hard to do a dynamic extend. And it seems almost impossible to find a short and elegant solution for that. So I decided to live with a fixed extend for now.

arctor

Link to comment
Share on other sites

Two other possible workarounds:

1) Make the window resizable.

2) When an item is selected, change the tooltip of the list box.

You could get really fancy with #2 and use the ToolTip function when the mouse is over a certain position (determined by LB_GETITEMRECT?) .... but the example just uses the tooltip parameter of GuiSetControlEx.

Global $WS_THICKFRAME = 0x40000;
Global $WS_MINIMIZEBOX = 0x20000;
Global $WS_MAXIMIZEBOX = 0x10000;
$winStyle = BitOr(BitOr($WS_THICKFRAME,$WS_MINIMIZEBOX),$WS_MAXIMIZEBOX)

Opt("GUINotifyMode", 1)
GuiCreate("MyGUI", 104,236,(@DesktopWidth-104)/2, (@DesktopHeight-236)/2 , $winStyle)

$list_1 = GUISetControl("list", "List 1", 10, 10, 60, 190)
GUISetControlData($list_1, "a really long entry|a second entry that is wide|a third long item")

$highlighted = "" ;keep track of selected listbox item so can update tooltip...

GuiShow()
While GuiMsg(0) >= 0
   sleep(100)
   
   If $highlighted <> GuiRead($list_1) Then
      $highlighted = GuiRead($list_1)
      GuiSetControlEx($list_1, -1, 0, $highlighted)
   EndIf
   
WEnd
Exit
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

You could get really fancy with #2 and use the ToolTip function when the mouse is over a certain position (determined by LB_GETITEMRECT?) ....

Not bad man! Not bad!

#2 is a good idea! Looks like just made for long records from a database to have a closer look. Even better than scrolling for miles. :D

I will try to get it to work with mouse over. Because it's faster to work doin the notify from the listbox than with an extra button.

arctor

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...