How to know the index of a node selection in a multiple selection? - cytoscape.js

Suppose you enabled box selection in cytoscapejs or you do something like:
cy.nodes().select();
when the user clicks a button. So, the user is able to select multiple nodes at once.
When registering the handler for the select event on nodes:
cy.nodes().on('select', function(evt){
...
}
Is there any way to know if the selection of a node is due to:
A single selection event (i.e. the user just clicked on a single node)?
A multiple selection event (and which index the current node is in this multiple selection)
Thanks!

You can track the events coming in to determine the type of selection (i.e. tap versus tapstart-tapdrag-tapend / tap versus box). You can keep a counter, declared outside the event callback, to track element indices if you want --- though the indicies won't really mean anything.

Related

Seeking suggestion to count time inside the loop

I am trying to measure/count the time inside the while loop, I tried a couple of methods but couldn't find the solution yet.
Here is my current VI.
 
In short, I am trying to measure the time as long as the "Boolean is on/true" and once it's off/false the time must be displayed.
If something is not clear then please let me know.
I may be repeating Fourier's answer, but typing it in two different forms may be helpful to you since I note you haven't accepted that answer yet.
Remove the outer While Loop. It is superfluous.
Then do this:
In the "turn on" frame, you gather the current Tick Count and stash it in a shift register. In the "turn off" frame, you gather the Tick Count again and subtract. In all the other frames, make sure you wire the two tunnels together so you don't lose your Tick Count. Side note: you probably want Boolean to be an indicator, not a control, so your user cannot click on it and toggle it directly.
You can reach your goal with simpler code. You should use one while loop only with the Event Structure:
When List of Conditions changes, intercept the event (as you are already doing) and register the time when this event happen (with the VI Tick count for example).
in two shift registers,"save" the time you registers in the previous point and the status of your count (a boolean should be enough: counting/not counting).
Then, in the Timeout event you calculate in real time the time passed with the following operation current time (Vi Tick count) - event time (save in the shift register).
You should count time only if your boolean Counting/not counting is True.
When you detect another event List of Conditions Value Change, you should check if you should stop count time or not.
Finally, in the Timeout event or in the List of Conditions Value change event, evaluate the stop condition for your while loop.

How can I set my ComboBox to allow the user to type in the first few characters and then automatically select the item by pressing ENTER?

I have a feeling this is a very simple thing that I'm overlooking.
I have two ComboBoxes that allow users to search for/select the record that they want to view. One is filled with Customer Names and the other is filled with Customer Numbers, so the user can look for a particular record by either selecting the Name or Number.
Each ComboBox is filled by a Data Table returned from a SQL Server database.
Each ComboBox has DropDownStyle set to DropDown, AutoCompleteMode set to SuggestAppend and AutoCompleteSource set to ListItems.
The user can either select by clicking the DropDown arrow and then clicking on the item they was or they can begin by typing and the ComboBox narrows the number of items in the list based on the characters the user is typing.
Using the mouse to click on the item in the list that they want works fine...it fires off a routine to retrieve the selected item from the database.
However, when the user types in the desired selection and presses ENTER, nothing happens. They must click the DropDown arrow and click on the item in order for the program to pull the appropriate record.
How do I get the ComboBox to pull the appropriate record when the user hits enter?
I'm using Visual Basic.
From the sounds of it, you need three events.
You need to use a timer to know when the user has stopped typing. To do that, you need one event would be when that field they're typing in has it's value change (<control's name>.TextChanged). That would start/restart a timer ticking (so that the user has a couple seconds to pause before the next event fires).
The next event would be the Tick event for that timer. That event would stop the timer, and then give focus to the right field so that when the user hits ENTER, they're not hitting ENTER in the field they've been typing in. You'll need to write a function to look up the right item in the ComboBox and call that.
Then you'd have a third event, either KeyPress, KeyDown, or KeyUp on the ComboBox itself. I'd lean towards the KeyUp to avoid issues if the user holds ENTER for whatever reason. That'd be what selects the item.
As a final FYI, I'm assuming you're using Visual Studio to write your code. If not, you should, and if you are/once you are, you can select the field you want to work with in the drop-down at the top left of the editor and then look at the associated events in the top right drop-down.
Thank you to JMichael for getting me on the right track with this one. I'm posting my solution here just in case it helps someone who has a similar question in the future:
The code that I added to the ComboBox's SelectionChangeCommitted event needed also to be added to the ComboBox's KeyUp event:
Private Sub cboPolicySearch_KeyUp(sended as Object, e As KeyEventArgs) Handles cboPolicySearch.KeyUp
If e.KeyCode = Keys.Enter Then
GetSelectedPolicySearchRecord()
e.Handled = True
End If
End Sub 'cboPolicySearch_KeyUp
The GetSelectedPolicySearchRecord() sub contained all of the information I needed to call my SQL Stored Procedure to select the data for the record that the user selected in the ComboBox.
Previously, this was only being called from the ComboBox's "SelectionChangeCommitted" event which is executed when the user clicks the drop down and then clicks a policy number from the drop down list.
I needed to add the same call to the GetSelectedPolicySearchRecord in the ComboBox's "KeyUp" event for when the user presses enter.

VBA event handler for checking cells in a table in Word

I have a table in Word:
Table Example
The table is bookmarked in the document, as it can appear in different places in the document. I access the table using the bookmark like this:
Set Tbl = ActiveDocument.Bookmarks("bookmarkname").Range.Tables(1)
I have a script that checks if a cell has a checkmark and displays a Msgbox when it has a checkmark and shouldn’t, based on certain criteria of the Row and Column name.
Here’s the question:
I would like this script to fire by a Cell_OnLeave type of event, so that when user leaves a cell, script will run. Is this possible?
If this is not possible, I would like the script to fire when user leaves the table, and script can check the whole table? Maybe a bookmark_deselected event would work for that? How could this be done?
It is possible to create custom events for table cells in Word.
Since the code is quite long, I'll just link to an example document and a GitHub gist.
I tried to comment the code as much as possible to make it understandable.
The module creates on enter, on change and on exit events for table cells and an event manager to define each event's behavior.
If you don't want to read everything, use the module by modifying the CellEventManager subroutine.
The sub receives the event type and the cell that triggered the event, so you can properly define event responses to your likings.
I also implemented a Cancel functionality for the OnExit event: Set CellEventManager = Fail during the handling of a OnExit event to prevent the selection from leaving the cell.
Only the built-in events can be handled in Word. There are no specific events for either tables or bookmarks. The only event that gets you anywhere close is the WindowSelectionChange event which fires each time the selection is changed, i.e. each time the insertion point is moved.

VBA - insert objects next to each other

I have some VBA code, such that when a button is pressed, the user can choose a file from their computer, and insert it as an object that looks like an icon into the spreadsheet.
The code is such that it counts each time the button is clicked, so each new icon inserted by the user appears to the right of the existing one, i.e:
count = count + 1
ActiveSheet.Shapes("Object 1").IncrementLeft 90*count
Now, the problem is, I don't know how to change the count so that each time a user deletes an object from the spreadsheet, the count would decrease by 1 (so that the next object inserted would still be in line and the appropriate spacing to the right of the first object). I would assume that I would use an event, but there doesnt seem to be an event for when an object is deleted.
Any advice?
Since the embedded files are OLE objects then you don't need to maintain a count. You can just calculate it on the fly using the OLEObjects collection.
If there are other ActiveX objects then you might need to need to iterate through and just count the items of type xlOLEEmbed.
Count = 0
For Each o In Sheet1.OLEObjects
If o.OLEType = xlOLEEmbed Then Count = Count + 1
Next
How do you handle the deletes?
Maybe you can prompt the user to press a button to delete beforehand.
So user presses a button, you see how many objects are in whatever field you're referencing, and then keep scanning each time the user initiates something.
Either way you're going to have to have some way for the to track each time the user initiates something. Or you can track by selection; IE if user selects one of the objects, see how many objects remain, after each action performed by the user.
Presumably they're only selecting it in order to delete.

Gray out a form row's (detail's) button conditionally with VBA code

I have a standard form in MS-Access which lists a bunch of orders, and each row contains order no, customer, etc fields + a button to view notes and attached document files.
On request from our customer we should gray out the button btnAnm (or check or uncheck a checkbox) depending on a calculation from two queries to two other tables (a SELECT COUNT WHERE and a check if a text field is empty).
I've tried btnAnm_BeforeUpdate(...) and btnAnm_BeforeRender(...) and put breakpoints in the subs, but none of them trigger. The same if I use the control Ordernr instead of btnAnm.
I'd like a function in the Detail VBA code to be triggered for each "Me." (row) so to speak, and set the row's control's properties in that sub.
What do I do? I've looked at the help file and searched here.
*Edit: So I want to do something that "isn't made to work that way"? Ie. events are not triggered in Details.
As an alternative, could I base the value of a checkbox on each line on a query based on the 'Ordernr' field of the current row and the result of a SELECT COUNT from another table and empty field check?
Do I do this in the query the list is based on, or can I bind the extra checkbox field to a query?
A description of how to do this (combine a COUNT and a WHERE "not empty" to yes/no checkbox value) would be perfectly acceptable, I think! :)*
You cannot do much with an unbound control in a continuous form, anything you do will only apply to the current record. You can use a bound control with a click event so that it acts like a button.
Presumably the related documents have a reference to the order number that appears on your form, which means that you can create a control, let us call it CountOrders, with a ControlSource like so:
=DCount("OrderID","QueryName","OrderID=" & [OrderID])
The control can be hidden, or you can set it up to return true or False for use with a textbox, you can also use it for Conditional Formatting, but sadly, not for command buttons.
Expression Is [CountOrders]>0
You can also hide the contents and add a click event so that is acts in place of the command button. Conditional Formatting will allow you to enable or disable a textbox.
As I understand your question, you have a continuous form with as command button that appears on each row - and you'd like to enable/disable the button conditionally depending on the contents of the row.
Unfortunately you can't do that. It seems that you can't reference the individual command buttons separately.
Having wanted to do something similar in the past I came up with two alternate ways of setting up my interface.
Put a trap into the onClick code for the Button. Which is icky, because it is counter intuitive to the user. But it gets you that functionality now.
Move the command button (and editable fields) up into the form header, and make the rows read only. Your users then interact with the record only in the header, and select the record they want work with in the list below. As I recall this is known a Master-Detail interface.