Jump to content

ComboBox Troubles


ame1011
 Share

Recommended Posts

Hi, I'm having a bit of a problem with combo boxes in the app that I'm currently developing.

The comboBox in question serves as a userlist, it contains strings formatted as follows:

lastname, Firstname_______________________PhoneNumber

My first problem is that I tried adding tab indents -- Chr(9) -- to separate the names + phone numbers so that the column of phone numbers is lined up, but the combobox doesn't accept those characters and displays them as boxes. I then tried adding an equal number of spaces to each line but because some letters are bigger than others that also didn't work. Anyone have any other ideas?

Additionally, when a user on the list is selected, instead of displaying the whole string (name + phone) in the selection box, only the name is displayed with the _GUICtrlComboBox_ReplaceEditSel function. The problem with this is that the box scrolls all the way to the right so that the first few letters of the name replaced is hidden even though there is more than enough room to display the whole name without cutting anything off. Anyone know how to fix this as well?

Finally, is there any way to change the selection color bg as well as the selected color text in the dropdown?

Those familiar with quickbooks, I am trying to achieve the same functionality.

Thanks for your time

Edited by ame1011
[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

Here's one technique, using a fixed width font:

#include <GuiConstants.au3>
#include <String.au3>

Opt("GuiOnEventMode", 1)

Global $avNames[4] = ["Brady, Tom, (123)456-7890", "Manning, Eli, (234)567-8901", _
    "Burris, Plaxico, (345)678-9012", "Brown, Charlie, (456)789-0123"]

Global $hGUI = GUICreate("Test", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
Global $ctrlCombo1 = GUICtrlCreateCombo("Variable Spacing (Default)", 10, 10, 380, 100)
Global $ctrlCombo2 = GUICtrlCreateCombo("Fixed Width (Lucida Console)", 10, 50, 380, 100)
GUICtrlSetFont($ctrlCombo2, 9, 400, 0, "Lucida Console")
For $n = 0 to 3
    $avSplit = StringSplit($avNames[$n], ",")
    $sNameString = StringStripWS($avSplit[1], 3) & ", " & StringStripWS($avSplit[2], 3)
    $sPhoneString = StringStripWS($avSplit[3], 3)
    $sSpaces = _StringRepeat(" ", 40 - StringLen($sNameString) - StringLen($sPhoneString))
    GUICtrlSetData($ctrlCombo1, $sNameString & $sSpaces & $sPhoneString)
    GUICtrlSetData($ctrlCombo2, $sNameString & $sSpaces & $sPhoneString)
Next
GUISetState()

While 1
    Sleep(20)
WEnd

Func _Quit()
    Exit
EndFunc

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for the response, I was trying to keep the font uniform accross my program but I did finally cave in and used a fixed-width font.

My 'scrolling to the right' problem still exists though. If I set the edit text using the ComboBox functions in the helpfile, the cursor in the edit box is scrolled all the way to the right so that the beginning of the names are cut off and you need to manually scroll back to the left. Anyone know how to fix this?

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

Thanks for the response, I was trying to keep the font uniform accross my program but I did finally cave in and used a fixed-width font.

My 'scrolling to the right' problem still exists though. If I set the edit text using the ComboBox functions in the helpfile, the cursor in the edit box is scrolled all the way to the right so that the beginning of the names are cut off and you need to manually scroll back to the left. Anyone know how to fix this?

Post a short reproducer script so we can see your issue.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GuiComboBox.au3>
#include <ButtonConstants.au3>

Global $FontName2 = "Lucida Console"

;Gui Creation
$ScheduleTeeOff = GUICreate("Schedule Tee Off", 801, 501, 195, 126)
GUISetBkColor(0xFBFAFA)


;player dropdown
Dim $pList [4][3]
$pList[0][0] =  3
$pList[1][2] =  "Doe, John                     (xxx) xxx-xxxx"
$pList[2][2] =  "Doe, Jane                     (xxx) xxx-xxxx"
$pList[3][2] =  "Potts, Paul                   (xxx) xxx-xxxx"
$pListString = ""

for $x = 1 to $pList[0][0]
    $pListString &= $pList[$x][2] & "|"
Next

$ePlayer = GUICtrlCreateCombo ("Select a Player ...", 18, 130, 205, 25)
GUICtrlSetData($ePlayer, $pListString)
GUICtrlSetFont(-1, 10, 400, 0, $FontName2)
_GUICtrlComboBox_SetDroppedWidth($ePlayer, 358)

GUISetState(@SW_SHOW)

While 1
    Sleep(20)
WEnd

Func _Quit()
    Exit
EndFunc

Edited by ame1011
[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

All you need is fewer spaces between the name and phone number. Look more closely at how my script posted earlier assembles the string with a variable number of spaces, based on the string lengths of the name and phone number.

Fitting it in statically only required changing your input data:

;player dropdown
Dim $pList[4][3]
$pList[0][0] = 3
$pList[1][2] = "Doe, John            (xxx) xxx-xxxx"
$pList[2][2] = "Doe, Jane            (xxx) xxx-xxxx"
$pList[3][2] = "Potts, Paul          (xxx) xxx-xxxx"

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

All you need is fewer spaces between the name and phone number. Look more closely at how my script posted earlier assembles the string with a variable number of spaces, based on the string lengths of the name and phone number.

Fitting it in statically only required changing your input data:

;player dropdown
Dim $pList[4][3]
$pList[0][0] = 3
$pList[1][2] = "Doe, John            (xxx) xxx-xxxx"
$pList[2][2] = "Doe, Jane            (xxx) xxx-xxxx"
$pList[3][2] = "Potts, Paul          (xxx) xxx-xxxx"

:)

even with that many spaces, the selection box is still scrolled to the right on selection. I also have to ensure there is enough room there for long names so a small space like that is not going to work. Additionally, I only want the name displayed when an item is selected, not the whole name + phone number combo. If the combo was scrolled all the way to the left, the phone number would not be visible.

I also tried another method where if a item is selected, the text string is trimmed down to only lastname,firstname and that info is set with '_GUICtrlComboBox_ReplaceEditSel' but that still scrolls the box to the right even if the text being replace is 6/7 characters long

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

even with that many spaces, the selection box is still scrolled to the right on selection. I also have to ensure there is enough room there for long names so a small space like that is not going to work. Additionally, I only want the name displayed when an item is selected, not the whole name + phone number combo. If the combo was scrolled all the way to the left, the phone number would not be visible.

I also tried another method where if a item is selected, the text string is trimmed down to only lastname,firstname and that info is set with '_GUICtrlComboBox_ReplaceEditSel' but that still scrolls the box to the right even if the text being replace is 6/7 characters long

Ah. I get it now. Try this:
$binComboStyle = BitXOR($GUI_SS_DEFAULT_COMBO, $CBS_AUTOHSCROLL)
$ePlayer = GUICtrlCreateCombo("Select a Player ...", 18, 130, 205, 25, $binComboStyle)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ah i managed to figure it out and came here to tell you so, thanks for all your help. :)

When I select an Item the text in the selection box is highlighted, is there any way to remove this?

It's not a big deal but it's a bit annoying, thanks in advance.

Also, is there any way to highlight an item in an open combo list? IE. The user begins typing in the required name and as they are typing the combo updates to the closest match.

Edited by ame1011
[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
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...