ComboBox in gtk2hs, glade - combobox

I have created Window, ComboBox, Buttons using glade and the code as following:
module Main where
import Graphics.UI.Gtk
import Graphics.UI.Gtk.Glade
main = do
initGUI
Just xml <- xmlNew "Tp.glade"
window <- xmlGetWidget xml castToWindow "window1"
button <- xmlGetWidget xml castToButton "button1"
comboBox <- xmlGetWidget xml castToComboBox "combobox1"
onClicked button $ do
putStrLn $ "Apply button selected "
selected <- comboBoxGetActiveText comboBox
print selected
onDestroy window mainQuit
widgetShowAll window
mainGUI
If I select an option from the ComboBox and clicks the action button it shows the following error message
UI.exe: user error (Pattern match failure in do expression at gtk\Graphics\UI\G
tk\MenuComboToolbar\ComboBox.chs.pp:244:2-13)
Do I need to have separate Function for the action to be performed when I choose an option from the ComboBox? Please help me!!

As stated in the Gtk2Hs docs, comboBoxGetActiveText "returns the currently active string in comboBox or Nothing if none is selected. Note that you can only use this function with combo boxes constructed with comboBoxNewText."
If you want to use this function, try one of the following options:
don't set the TreeModel of the combobox (probably a ListStore) in the Glade file and add the line comboBoxSetModelText comboBox after the line comboBox <- xmlGetWidget xml castToComboBox "combobox1". This might work right because comboBoxNewText "internally calls comboBoxSetModelText after creating a new combo box".
remove the combo box widget from the Glade file, create it yourself (replace the line comboBox <- xmlGetWidget xml castToComboBox "combobox1" with comboBox <- comboBoxNewText and pack it manually into the main window of your program.
Note that TreeModels can hold any type of data. Since Haskell works with data in a different way than imperative languages as C or Python, tree models created with Glade can't be imported into a Haskell application: you must define them inside your Haskell program.

If you use the comboBoxGetActive function, it will return an Int and you can then make a mapping to each element in the comboBox. This is found in the Graphics.UI.Gtk.MenuComboToolbar.ComboBox API.

Related

Passing text to a combobox VB6

Have a question - I'm having an issue with passing .text to a combobox that has a style set to LIST. I'm not sure why the issue is. Basically have a combobox that's populated with a lot of data. To make matter simple, I've created an additional form where user has a whole screen from where they are able to choose an item. The new form has the SAME EXACT items that combobox has - so when I pass the text from the new form to Combobox 2.0 - I get an error 380 - text propery is not set correctly
are you using the .AddItem method to add your text items?

Combobox List passing string

I have a VB6 application that has been running for quite sometime. Currently I'm trying to update one of the form that has a combobox 2.0. Because the combobox is populated with hundreds of items - I'm trying to update it so that users are able to click on a look up button next to it, where another window opens up with all the items from the combobox. User will be able to search by keyword and/or select an item and double click on it and have it appear in the combobox. The issue I'm having is with trying to pass no value or "" when CANCEL is clicked. I'm able to pass the value if I in the properties window my STYLE Is set to COMBO rather than list. However, the issue I come across is that with COMBO the value (text) in the combobox sometimes is not aligned properly. Is there a way to pass a "" value to a combobox 2.0 without changing the style to COMBO?
If they hit cancel set the ListIndex of your combo to -1 rather than setting the text property. This is the value for no item being selected.

PyGTK ComboBox: how to populate when down-arrow is clicked

(PyGTK 2.24.2 with 32-bit Python 2.7.11.)
How do I populate a ComboBox dynamically when the down-arrow is clicked? I want the box to list the Windows COM ports (retrieved via win32file.QueryDosDevice) that exist at the moment it is clicked.
Create a callback function related to the "popdown" gtk.ComboBox Signal where you remove all texts in the connected liststore and add the new ones.
Definition (in your screen design, right after creating the combo):
self.combobox.connect ( 'popdown', self.callback )
Callback (best located in a separate part of the code):
def callback(self, combobox, user_param1, ...)
See http://www.pygtk.org/pygtk2reference/class-gtkcombobox.html#signal-gtkcombobox--popdown

Textbox Autocomplete Result

Win Form: Is there way to get the results from Auto Complete (FileSystemDirectories)? I am trying to write my own custom drop-down list instead of using the the original Textbox Control AutoComplete drop down list. However, I want to use the Textbox Auto Complete Source: FileSystemDirectories to display to my own custom drop-down list. How can I do it?

silverlight combobox - highlight a few items in the popup list

I'm wondering if I can make fake sections in the popup menu:
The rule would be, if the 5th character of the displayed item is different from the 5th char of the previous item in the menu, it has to be highlighted
What do you think?
Thanks!
To achieve this would be a hack.
Normally the items that appear in the popup part of a combo box will be an instantiated data template, and each gets its own data item and has no clue or knowledge of the other items in the list, so you couldn't use a converter or anything else to achieve this behavior.
What you could do though is inject (attach) your own control into the popup part of the combo box, and take over the rendering of the data items. How you do this will depend upon which combo box you are using (i.e. MS or some other vendor's) and would be a whole new question.
Would that be easier if I were to create my own combobox as follow:
a TextBox associated with a Button that when pushed would popup a datagrid in which I could implement this conditional formatting?

Resources