Jump to content

In the combo box, the selected item is not highlighted.


AndreyS
 Share

Recommended Posts

The simple solution is to change the ComboBox style a little:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiComboBox.au3>

Example()

Func Example()
  ; Create a GUI with various controls.
  Local $hGUI = GUICreate("Example", 300, 200)

  ; Create a combobox control.
  Local $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 20, $GUI_SS_DEFAULT_COMBO-$CBS_DROPDOWN+$CBS_DROPDOWNLIST)
  Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

  ; Add additional items to the combobox.
  GUICtrlSetData($idComboBox, "Item 2|Item 3|Item 3|Item 3|", "Item 2")

  ; Display the GUI.
  GUISetState(@SW_SHOW, $hGUI)

  Local $sComboRead = ""

  ; Loop until the user exits.
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE, $idClose
        ExitLoop

      Case $idComboBox
        $sComboRead = GUICtrlRead($idComboBox)
        MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI)

    EndSwitch
  WEnd

  ; Delete the previous GUI and all controls.
  GUIDelete($hGUI)
EndFunc   ;==>Example

If you are not happy with this control style, let me know and I'll see what I can do using the UDF functions.

The purpose of GUI Control creation functions is to make it easy and quick to get started for a new member without coding experience. But it's not a complete implementation of all control functionality and it has never been intended. For more control functionality, use the UDF functions.

 

I can see from a previous post that you are aware of the solution with the $CBS_DROPDOWNLIST style. I'll see what I can do with the UDF functions.

Edited by LarsJ
Bold line
Link to comment
Share on other sites

LarsJ, thanks for responding to help!

Yes, yes, I know that using the $CBS_DROPDOWNLIST property, you can ensure that the correct item is highlighted.
I wrote about this above in the subject:

Quote

There is actually one more option: using the $CBS_DROPDOWNLIST property.
But then you can’t enter text in combo, and this is a very important and necessary function for searching.

But as I pointed out, it is important for me that the combo retains the ability to enter text and select it with the mouse. And if you use the property $CBS_DROPDOWNLIST, then this opportunity is lost.

I would be very grateful if you would suggest how you can achieve both? Well, or as an expert said that this is generally impossible in the AutoIt language.

Edited by AndreyS
Link to comment
Share on other sites

As for the Windows standard controls, all functionality can be implemented in AutoIt.

The only option in your special case is probably to implement an Owner-Drawn ComboBox. I'll add an example that supports correct selection of multiple items with the same text in this thread. But at least I need the weekend and maybe all Christmas depending on how much time I can find to code AutoIt.

Edited by LarsJ
Link to comment
Share on other sites

Wow! LarsJ, so then it is too expensive and not profitable to already develop your own combo control!

Are you sure that, for example, in programs written in C, combo also behave incorrectly?

I still hope that there is a simpler solution to this problem. Indeed, even the $CBS_DROPDOWNLIST property changes its behavior.

Link to comment
Share on other sites

May 2012. Michael Sun (from Microsoft) answered a guy who had a similar problem, in this link.
He proposed a workaround as there is no solution for this. Here are some sentences found in the link :

- Michael Sun : "We are not saying that we cannot put duplicate values into the ComboBox. Actually, I just feel confused. If an app put duplicate values in the ComboBox, I will feel confused which one should I select. What's the difference between the duplicate values ?   

In my post, I provided a workaround which can prevent the SelectedIndex changing to the first item named chris. However, if we open the ComboBox again, its SelectedIndex value will change back to the first item named chris. I don't think the issue can be easily fixed since it's related to the underlying Win32 control in the OS level. Could you please make the three "chris" in the ComboBox be a little different?"

- OP : "if I should not use duplicate values means why the combo box allows me to add the values, why the combobox is not throwing any exception while binding itself., and why selectedvalue is property given ?"

- Michael Sun : "Please try my workaround and let me know the result.  I cannot figure out other ways right now since it's related to an OS level issue as I mentioned in my last post."

Link to comment
Share on other sites

Wow! Thank you very much, pixelsearch, for even finding such material!
This is valuable information!

I re-read the topic on their forum. There really is the same situation as my situation and the justification for the need to use the same items. I realized that this is really a flaw in the implementation of combos or OS. And, worst of all, this problem is unlikely to be fixed by the creators.

Then it seems you need to use only some workarounds to solve this problem. :(

Link to comment
Share on other sites

  • 2 months later...

Obligatory: I'm not a professional at this, just hobbyist.

If you can get the index of what you selected with

_GUICtrlComboBox_GetCurSel($idComboBox)

and if you have some identification other than name (preferably a number) you can compare that number to the other one and load the correct thumbnail.

I'm currently writing a program that also lists people's names (to keep track of which characters belong to which player if I know their name because i suck at remembering such things) and I use SQLite database which requires to use an ID column
I also use the same ID for the name of the thumbnail so I can just get it with

GUICtrlSetImage($cthumbnail, "thumbnails/"&$return[8]&".bmp")

where the array variable $return[8] contains the ID number in this example.

Hope this helps.

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...