I am trying to write a program that selects and focuses a specific item in a list view.
Why is calling ListView_SetSelectionMark (or sending LVM_SETSELECTIONMARK) not working to set focus on a list view item? After calling ListView_SetSelectionMark, the focus remains where it was rather than changing to the new location; when I press an arrow key it moves from the previously focused item rather than the item I specified.
Here is my snippet of code that selects and focuses an item:
ListView_SetItemState(this->m_hwndChild, index, LVNI_SELECTED, LVNI_SELECTED);
ListView_SetSelectionMark(this->m_hwndChild, index);
ListView_EnsureVisible(this->m_hwndChild, index, false);
SetFocus(this->m_hwndChild);
Here is a full gist. Each time you press Ctrl-R, it selects a random item of the list view.
The SelectionMark has nothing to do with focus. It merely indicates which item starts a multiple selection.
You need to use the LVIS_FOCUSED item state instead:
ListView_SetItemState(this->m_hwndChild, index, LVNI_SELECTED | LVNI_FOCUSED, LVNI_SELECTED | LVNI_FOCUSED);
ListView_EnsureVisible(this->m_hwndChild, index, false);
SetFocus(this->m_hwndChild);
Related
My goal is to Programmatically select items from the List of the combo box, but without updating the edit control. The same can be achieved with the mouse. E.g. when you drop down and hover an item from the list, that item is highlited. And that is all. If you want to select in it the combo box (e.g. move it to the edit control) - you must click on the LisBox.
I tried with CB_SELECTSTRING. But it automatically updates the ComboBox edit control with the selected text which is not what I want. I want to do this using raw Win32 or VB6
Thanks
There is a big difference between highlighting an item in the drop-down list and actually selecting an item to make it active. CB_SELECTSTRING selects an item, as its name implies. But there is no official ComboBox API to highlight an item, though.
However, you can display the drop-down list manually (CB_SHOWDROPDOWN), and either:
move the mouse over the desired item so the list can perform hot-tracking logic.
manipulate the list directly. Use CB_GETCOMBOBOXINFO or GetComboBoxInfo() to get the list's HWND, and then send LB_SETCURSEL to it.
It is trivial to setup NSPopUpButton's menu via binding with an NSArrayController. A slightly more complicated, but very frequent use case, is to use NSContentPlacementTagBindingOption to insert the array items into the menu from a specified index. A nice example of this is given here, NSPopUpButton + Bindings + Show All Option.
For example, say I have, the following UI which uses a popup to select a column from a table view. Because the column can be added and removed dynamically by the user the menu items need to be synchronised with model,
_________________
Select table column: |____None_________| <--- this is the popup
The menu could have the following items,
_______________
| None | <-- Out of model item, "None" or empty selection
------------- <-- Out of model item, separator item
| column 1 | <-- These are dynamically replaced menu
| column 2 | item done using bindings and the
| column 3 | NSContentPlacementTagBindingOption
|_____________| option from IB.
Notice that there are two non-model-items in the menu, they are inserted into the UI in IB before the the content replaced tag. Using the content replacement tag massively simplifies populating the menu and keeping the items synchronised with the model. However, this causes huge problems when the uses makes a selection which is outside the content of the bound array: the "None" marker and the the separator item. Because they are outside the array they cannot become selected items. So the popup button's selected object binding cannot be use to track selection changes from UI to model.
Has anybody found a successful way of working with NSContentPlacementTagBindingOption, NSPopUpButton and non-model (static) items in the menu?
I'm pretty much about ready to give up and populate the menu manually, which would suck.
NSPopUpButton needs to accept two array controllers: one for static content (the none and separator) and the one for dynamic content which works with content replacement tags. This would make all choices valid.
the standard behaviour of a Flex dropdownlist is to disable the currently selected item from the list. Does anybody know how to override this to allow the user to re-select the selected item (if they so desire)?
NOTE: I don't want there to be a selected item in the list but I still want the selecteditem property to be set in the dropdownlist control, otherwise how will I know what has been selected. This is slighly trickier than it sounds...unless I have missed something...
Thanks
Mark
I'm not sure I understand the question but you can listen to close event of the component :
Dispatched when the drop-down list closes for any reason, such when the user: Selects an item in the drop-down list. Clicks outside of the drop-down list. Clicks the anchor button while the drop-down list is displayed.
So, you can access the component and gather the selectedIndex, selectedItem properties.
I guess what I'd like to know is that why you want to "re-select", possible to trigger something again but I'd try close event...
Telerik on first selection of any item other than first is always resetting to first item and it does not fire the selectedindexchange event. However, when the combobox is selected for a second time, the event fires.
Does anyone have any suggestions as to why this occurs?
Right it only fires when the item changes, so first item is not technically a change of the selection since it defaults to zero. A workaround is to add a default blank item, and force a selection through the RequiredFieldValidator control.
I have a Datawindow Grid in a window I've created and one column of this DW has as its data, different menu paths that are the same of the menus and submenus I have created. The point is that when I double-click on every DW row, I want to execute the clicked event of the different menu path that is stored as data in each row.
For example the first row is "m_epith_frame.m_parms_su.m_poi.m_poi_ergast", the second is "m_appl_frame.m_1_sb.m_2_sb" etc.
I know that when in scripts, I write m_epith_frame.m_parms_su.m_poi.m_poi_ergast.Clicked(), it triggers the Clicked event of this menu item and for example opens a form...
So how can I click each row and trigger the clicked event for every menu path of each row?
It is, I suppose, a dynamic event call problem, but I can not find any solution..
Thanks in advance
You can recurse menus to build up a string array of the menu paths. At the same time build up an array of the menu items and assign the menuitem object to this using the same array index number as for the strings. Don't use create, just assign the menuitem to the array.
When someone clicks on a row, find the index of the path in the string array, then trigger a click event on the menu item array using the same index.
The menu item array holds pointers to the real menu items in the menu, so it's the same as clicking on the menu option, e.g you can code
im_menuitems[li_menuindex].Triggerevent (Clicked!)
and if this is m_epith_frame.m_parms_su.m_poi.m_poi_ergast that is what is clicked.