AndreyS Posted December 16, 2019 Share Posted December 16, 2019 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. expandcollapse popup#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 comment Share on other sites More sharing options...
FrancescoDiMuro Posted December 17, 2019 Share Posted December 17, 2019 @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: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
AndreyS Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) 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 December 17, 2019 by AndreyS Link to comment Share on other sites More sharing options...
Nine Posted December 17, 2019 Share Posted December 17, 2019 (edited) @AndreyS You will have to add something after the duplicate elements like (2), (3), so the combo can distinguish between them Edited December 17, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AndreyS Posted December 17, 2019 Author Share Posted December 17, 2019 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 comment Share on other sites More sharing options...
FrancescoDiMuro Posted December 17, 2019 Share Posted December 17, 2019 @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: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Nine Posted December 17, 2019 Share Posted December 17, 2019 (edited) 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 December 17, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AndreyS Posted December 17, 2019 Author Share Posted December 17, 2019 I’ll be very easy to distinguish. I have several identical names in combo. And choosing their names in turn, I see their photos and other data in other controls. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted December 17, 2019 Share Posted December 17, 2019 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: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Nine Posted December 17, 2019 Share Posted December 17, 2019 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 FrancescoDiMuro 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
LarsJ Posted December 18, 2019 Share Posted December 18, 2019 Use the UDF functions. And then use index instead of name. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted December 18, 2019 Share Posted December 18, 2019 (edited) @LarsJ Are you suggesting to use _GUICtrlComboBox_SetCurSel(), for example? Edited December 18, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Nine Posted December 18, 2019 Share Posted December 18, 2019 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AndreyS Posted December 18, 2019 Author Share Posted December 18, 2019 (edited) 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. expandcollapse popup#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 December 18, 2019 by AndreyS Link to comment Share on other sites More sharing options...
pixelsearch Posted December 18, 2019 Share Posted December 18, 2019 (edited) 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 expandcollapse popup#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 December 18, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
AndreyS Posted December 18, 2019 Author Share Posted December 18, 2019 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 comment Share on other sites More sharing options...
Nine Posted December 18, 2019 Share Posted December 18, 2019 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$. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AndreyS Posted December 18, 2019 Author Share Posted December 18, 2019 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 comment Share on other sites More sharing options...
Nine Posted December 18, 2019 Share Posted December 18, 2019 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AndreyS Posted December 18, 2019 Author Share Posted December 18, 2019 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 comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now