How do I get the target of Control Click in NSOutlineView - nsoutlineview

I have a NSOutlineView controlled by a NSTreeController.
NSOutlineView is connected to a Contextual Menu in Interface Builder.
Control Click brings up my Menu, and the row clicked on is "selected" with a pale highlight with a border.
I can't seem to find any way to find which row is "selected".
selectionIndexPath and selectedObjects are nil.

You want to use clickedRow. Note that this becomes a bit more complicated if you support multiple selection, because the selection gets targeted by the shortcut menu if the clicked row is within it, whereas if you click elsewhere, the (single) clicked row is the target and the selection is ignored.
Here's an example of some code I wrote to handle this:
- (NSArray *)selectedURLs;
{
NSInteger clickedRow = [outlineView clickedRow];
NSArray *selectedObjects;
if (clickedRow == -1 || [[outlineView selectedRowIndexes] containsIndex:clickedRow])
selectedObjects = [treeController selectedObjects];
else
selectedObjects = [NSArray arrayWithObject:[[outlineView itemAtRow:clickedRow] representedObject]];
return [selectedObjects valueForKey:SSTreeNodeAttributes.fileReferenceURL];
}

Related

How to focus on a ToolStripTextBox (one of the items in a ToolStripDropDownButton.DropDownItems collection) when the drop down opens

I'm building the DropDownItems of a ToolStripDropDownButton programmatically. The first field is always a ToolStripTextBox (which users can type into to filter the following items). I want the ToolStripTextBox to have focus as soon as the drop down opens so that user can:
Click on the ToolStripDropDownButton
Begin typing (to filter the items)
However, when I try to focus on the ToolStripTextBox (within the DropDownOpened event handler):
Dim v As ToolStripTextBox = DirectCast(tsbForms.DropDownItems(0), ToolStripTextBox)
Me.ActiveControl = v.Control
I get an exception:
System.ArgumentException: 'Invisible or disabled control cannot be activated'
Here's a screen shot of the dropdown so you can see what I'm talking about:
Currently the textbox at the top doesn't have focus and you have to click in it before you can start typing in the filter.
FYI I've tried testing the Visibility of the ToolStripTextBox before setting ActiveControl and it is True in this event. I've tried performing the operation a few other events and got the same result.
Just setting focus worked for me:
Dim v As ToolStripTextBox = DirectCast(tsbForms.DropDownItems(0), ToolStripTextBox)
v.Focus()
I used the DropDownOpened event of the parent ToolStripDropDownButton.

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.

How to add CheckBoxes to a ComboBox?

I want to create a ComboBox having Checkboxes as children using Codename one.
I am not using the UIBuilder
For reusability I created a Container having three Checkboxes in it:
OverviewCheckBoxContainer
- Checkbox1
- Checkbox2
- Checkbox3
and this works already.
As it takes too much space on the screen, I now tried to add the CheckBoxContainer into a Combobox, like this:
ComboBox
- OverviewCheckBoxCont
-...
but it does not work, the ComboBox contains a single entry only and it's not a checkbox, but a text:
OverviewCheckBoxCont[x=...
(cannot see further on the screen)
How can I solve this issue, so there is a dropdown menu containing the three Checkboxes, that toggle onClick?
ps:
In the main form I added the CheckBoxesComboBox instead of the CheckBoxesCont:
this.add(BorderLayout.CENTER, checkBoxesComboBox)
instead of
this.add(BorderLayout.CENTER, checkBoxesCont)
1.You can use simple combobox as shown below
ArrayList al = new ArrayList();
findComboBox().setModel(new DefaultListModel(al));
2.And to add checkbox in combobox , you have to customize the combobox
3.Instead of customizing combobox, You can use button which shows and hides OverviewCheckBoxContainer which contains list of checkboxs
See this for customizing the ComboBox with the generic list cell renderer: https://www.codenameone.com/manual/components.html#_combobox
The problem with using checkboxes in a combo is that you would assume they would all appear in the combo as a set and the combo wasn't designed to do that. I would instead just use a Button and show a dialog with a set of checkboxes then set the text of the Button to match the result. You can style the button to look like a ComboBox if that is your preference.

WPF Exiting "Dropped" Combobox, Items no longer editable?

Friends,
I have a WPF Combobox. When the Combobox is opened, I have the items dynamically generated based upon environment variables. So basically a combobox that is bound to a list that is dynamically changing.
Everything works as expected until I Exit the combobox with the dropdown open to enter another control(another combobox).
When I reopen the first combobox, the items appear to be frozen and no longer bound to the list when INDEED the list is changing and is still bound. Its almost like the binding broke.
When this event occurs, I have attempted to forcefully add items, and that doesn't work either. I can see in the code behind that the combobox now contains the additional items, yet it doesn't appear that contain them in the UI.
What is this black magic? Any way to prevent it? is this some type of Stuck focus issue? Maybe the dropdown isn't re-sizing?
I think i have narrowed it down to the physical dropdown is not re-sizing to the new items.
EDIT*
The controls are dynamically generating, so I have no real hard code to show you other than this.
private void CBControl_DropDownOpened(object sender, EventArgs e)
{
((ComboBox)sender).Items.Add("Option");
}
On this event, I will add an items to the combobox, although the items ARE being added to the list, they are not displayed in the UI.
EDIT 2*
I figured it out, so i have 2 comboboxes, it appears that the 2nd was steeling and holding the focus INSIDE the dropdown. (odd bug)
in order to fix it i needed to release it bu changing the index of the 2nd combo box WHILE it is open.
int sel = ComboBoxTwo.SelectedIndex;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = -1;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = sel;
and I had to manage the unintended recursive call.
So, here it is.
You got 2 ComboBoxes. If you Open one then directly click into another, the focus is moved to the second combobox dropdown.
If you make any changes to the first combobox, the changes will not take effect to the style(dropdown resize) UNTIL you release the focus from the 2nd combo box dropdown item. Although the items change will take effect, the resize wont.
to release the focus, you need to open the second combox and change the selected index like so:
int sel = ComboBoxTwo.SelectedIndex;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = -1;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = sel;
10 hours of debugging. 5 hours of research. First solution I have found. It may be dirty, but its all I can find.

Compatible value's position in an editable ComboBox

I have a ComboBox implemented with an auto-completion system. My ComboBox contains more than 100 items. When users are typing text in, the auto-completion system opens the dropdown list and highlights the most relevant item. Moreover, when the dropdown list is expanded, all items are available (no filters). But the most relevant item is always at the bottom of the dropdown list.
I would like it to be in the middle, if possible. One item can have the same reference but another type than another one, that's why I need to see most of them in my dropdown by placing them in the middle.
Any idea ? It's not really important but kind of useful for them. Thanks !
Update :
Here's my ComboBox with the open dropdown. Sorry about that, I had to blur its elements. As you can see, the user starts writting the reference in the ComboBox. The autocompletion works fine, but the corresponding item is found at the end of the dropdown list (in the red frame), almost out of bounds.
I wish it would be highlighted in the middle of my dropdown list instead of so far below.
Your item search may work well, but your list isn't visually filtered, which means it's size always remains the same.
It's scrolled into view, by the wpf system, but still displaying all other items around the relevant one. The reason why it's at the bottom is because wpf Scrollviewer just finished scrolling the item into view and sees no need to scroll it further into the middle.
You could use the CollectionViewSource class. Why ?
It's simple to use, will keep your viewmodel data as it is, and you would have your relevant completion item at the top. It can be obtained by GetDefaultView(..)
Let's say you have a viewmodel flag "IsHidden", stating that it's content does not match the user input:
ICollectionView cv= CollectionViewSource.GetDefaultView(myComboBox.ItemsSource);
// switch filter on
cv.Filter = obj => (obj as myViewModel).IsHidden == false;
// switch off
cv.Filter = null

Resources