Jump to content

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


Recommended Posts

Specialists, tell me, please, how to make sure that after manually selecting the last element in the combo (Item 3), it will be marked in the drop-down list. And it turns out that the first of the same elements is always selected.

It is important for me that the combo contains exactly the same elements.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.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)
    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

 

Link to post
Share on other sites

@AndreyS
That behaviour is explained in the Help file about GUICtrlSetData() function:

 

Remarks

For Combo or List control :
If the "data" corresponds to an already existing entry it is set as the default.

By the way, why would you need to have same elements in a ComboBox? :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
Share on other sites

No, no - it’s filling in just right!
And by default, the correct item is also selected!
But when you open the list for selection, the very first of the same elements is always highlighted.

I need the same values, as this combo contains the names of contacts that are repeated. And when I select a name in combo, then in another control a photo of this contact is displayed.

Edited by AndreyS
Link to post
Share on other sites

@AndreyS You will have to add something after the duplicate elements like (2), (3), so the combo can distinguish between them

Edited by Nine
Link to post
Share on other sites

I am very grateful for responding to help!
Yes, of course, adding something to make them unique is also a kind of solution. But I would not want to add extra and interfering characters to the names. Since they sometimes have to be copied from combo, extruded, and this adds unnecessary processing to the code.

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.

I would very much like to hear answers from AutoIt experts.

Link to post
Share on other sites

@Nine
Yes, you are right, but it works if you remove the last separator char as well.


@AndreyS
How will you differ the various images to display if the text you are going to check is the same for two or more images?
Only the index of the item differs :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
Share on other sites
2 minutes ago, FrancescoDiMuro said:

Yes, you are right, but it works if you remove the last separator char as well.

Not if you have only 1 item in the data...

Edited by Nine
Link to post
Share on other sites
7 minutes ago, Nine said:

Not if you have only 1 item in the list...

Could you please post an example of what you are saying? :)

@AndreyS
Not so simple as you are explaining... When you do a comparsion, and you have two same strings from which you want two different results, that is not gonna work as you are expecting.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
Share on other sites
GUICtrlSetData($idComboBox, "Item 2|Item 3|Item 2|Item3") ; will work with or without ending "|"
GUICtrlSetData($idComboBox, "Item 2") ; will not add to combo, will set default as help file
GUICtrlSetData($idComboBox, "Item 2|") ; will add to combo, not described in help file

I removed it from my post because I didn't want to hack OP thread, but I suppose it is kind of late now ;)

Link to post
Share on other sites

Ya I thought about this way, but still need to know which of the 3 Larsj to get the right photos and other stuff.  He will need some way to identify name individually without doubt.

Link to post
Share on other sites

Friends, it doesn’t matter how I further identify these names. I am using an array for this. Don't let it bother you.

It is important for me to solve only one question: how to make it so that when I select the last Item 3 in the combo, then this Item will be highlighted further when I select it, and not the first Item?

After all, the combo itself perfectly distinguishes between these Items, when I select the one I need, then it correctly selects this Item. But only the first one highlights. This is a mistake in his work or some kind of flaw.

#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)
    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)
                $sComboRead = _GUICtrlComboBox_GetCurSel($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

 

Edited by AndreyS
Link to post
Share on other sites
Just now, AndreyS said:

how to make it so that when I select the last Item 3 in the combo, then this Item will be highlighted further when I select it, and not the first Item?

This could work with a little restriction :  no space just before "|" inside the $sItems string

#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("", 10, 10, 185, 20)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Add all items to the combobox
    Local $sItems = "Item 0|Item 1|Item 2|Item 3|Item 3|Item 3"
    GUICtrlSetData($idComboBox, $sItems, "Item 2")

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

    Local $sItemRead, $iItemIndex, $iLeftDelim, $iRightDelim

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

            Case $idComboBox
                $sItemRead = GUICtrlRead($idComboBox)
                $iItemIndex = _GUICtrlComboBox_GetCurSel($idComboBox)
                MsgBox($MB_SYSTEMMODAL, $sItemRead, "ComboBox index: " & $iItemIndex, 0, $hGUI)
                $sItems = StringStripWS(StringReplace($sItems, " |", "|"), 2)
                $iLeftDelim = StringInStr($sItems, "|", 0, $iItemIndex)
                $iRightDelim = StringInStr($sItems, "|", 0, $iItemIndex + 1)
                $sItems = StringLeft($sItems, $iLeftDelim) & $sItemRead & " " & StringMid($sItems, $iRightDelim)
                GUICtrlSetData($idComboBox, "|" & $sItems, $sItemRead & " ")
        EndSwitch
    WEnd

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

 

Edited by pixelsearch
Link to post
Share on other sites

Well, yes, this is another way around this problem with combos. Thank you for your participation, pixelsearch!

But still, this again changes the data and adds an extra character, and it’s bad that it is inconspicuous. And this will interfere with the selection and copying of the current item shown in combo.

I need to get around this problem without any data changes.

I would like the creators of AutoIt to report on whether this can be fixed in the future and can this be circumvented in any way now?

Link to post
Share on other sites

I believe it is the basic behavior of the combo control of Windows, as it shouldn't have duplicates in it normally.  So I don't think it is AutoIt issue.  As for your requirement, you should think using another type of control that accept more easily duplicates, whether it is a listview or a treeview.  Just my 0.02$.

Link to post
Share on other sites

I do not think that the developers of Microsoft or AutoIt conceived this. Most likely they did not take this moment into account or did not complete the control.

If it were not for the developers to have the combo store the same items, then the developers would not at all give the opportunity to add and display them. And since they allowed to add the same items and see them in combos, then they should have made his reaction to their choices right.

Something here is clearly not right! I would like to still hear very much the experts and creators of AutoIt.

Link to post
Share on other sites
18 minutes ago, AndreyS said:

I would like to still hear very much the experts

I know you don't. But you should understand that you are very offensive with people who try to help you. I am out.

Link to post
Share on other sites

You're not right, 9! I have already thanked everyone and thank you for their participation! And for the fact that each provided options for circumventing this problem. But what interests me is the root of this problem and the best solutions. That is why I would like to hear someone from the language developers who know all the nuances and subtleties.

It’s possible my English is so bad that something sounded insulting to you. If so, then personally I apologize to you! And thanks again for your help!

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...