I am adding a right click functionality on individual nodes of a treeView in my C# code.
The options like "Add", "Delete", "Rename" should pop up when the user right clicks in those nodes on the tree. Now depending on the node that is being clicked, I am filling up the menu as using the following statememnts:
contextMenuStrip1.Items.Add("Add");
Then if a different nodes is right clicked I use the following:
contextMenuStrip1.Items.Add("Rename");
There are some nodes where both the items have to be shown:
contextMenuStrip1.Items.Add("Add");
contextMenuStrip1.Items.Add("Delete");
How do I write seperate event handlers for Add and Delete when both of them exist in the context menustrip. I am not able to differentiate whether "Add" or "Delete" was clicked. Currently I am using the "ItemClicked" event on the ContextMenuStrip to execute my piece of code in the event handler for "Add" but this evemt also gets raised when "Delete" is clicked. Any help would be appreciated.
Thanks,
Viren
Instantiate your context menu strip. In that you will add your three ToolstripMenuItems. Each toolstrip menu item will have it's own OnClick method. Change the visibility property of an item depending on what your context requires.
Related
Assuming the following HTML:
<div *nfFor="let option of options" (click)="option.check = !option.check; selectionChanged.emit(option)">
<input type="radio" [(ngModel)]="option.check" (ngModelChange)="selectionChanged.emit(option)"/>
...additional elements related to input
</div>
I want to prevent the event from being emitted twice when clicked on the div instead of directly on the input. As far as I know the click is only registered once, if clicked directly on the input it'll fire that but if clicked outside of the input but within the div it'll execute the (click) statement.
So anyway the question is wether there will be two emits on selectionChanged when clicked on the div as there's also an ngModelChange on the input element itself. Does ngModelChange recognize changes on the ngModel bound property from outside the element it is attached to and therefore fire?
NOTE: I know the radio button has two event bindings which isn't the right way to go about things in Angular (I think, two chefs in the kitchen?) but that's something i'll fix later if necessary
Hey I have a div which is wrapped by a Link component, and inside that div I have more buttons, but the problem is, when I click on the inner smaller buttons, I actually click on the Link component as well, so I get redirected which is not what I want... How do I fix this?
it seems as though both the link and the button get clicked but if i am intending to click the button only i want to avoid the parent link.
What I mean is, the Link is used to navigate to some URL when you click on it. Putting elements inside that for other tasks. like a blog post, you click on the parent it will redirect you, but on the child the button will allow you to delete it
was coding this in nodejs react so i was using onClick events
example
<Link to="/blog-post">
<div className="link-post-container">
...blog
<button className='deleteButton'></button>
</div>
</Link>
I have tried event.stopPropagation on the button but it still doesn't seem to do anything. Is it because the Link is an href instead of a onClick?
SOLUTION
so using some of the possible solutions below i started messing around and noticed by in the onClick of the deleteButton, if i add the following in, it works:
event.preventDefault()
with this, the redirect because of the href does not occur anymore and only the button click event will take place
const handleClick = event => {
event.stopPropagation()
// then write rest of your onclick code
}
<button className='deleteButton' onClick={handleClick}></button>
The click event propagates from the button upwards in the DOM tree until it reaches the root (simplified explanation - you can learn more about event propagation here). This is why the link also registers it and runs its onclick handler, redirecting you to another site.
You can call event.stopPropagation() inside your button's onClick handler to stop the event from reaching the encapsulating link.
source
Here is the link for an example of the issue I will attempt to describe. In the chips autocomplete example, click the text box to select a new fruit.
Now, before clicking anywhere else, click again on the text box as you did before.
This should result in no options showing up. The issue here is that the user must either begin keying in a new selection or first click another element in the window before matchip will show the options to choose from. I am wondering if there is a way to fix this issue. I would like a user to be able to choose a selection from the list and then immediately click the text box as they had before and make a new selection.
I'm using mat-chip-list inside an outer *ngFor iterating over a FormArray.
Here is what I'have done. It's pretty efficient :
<input
#validatorInput
#operationTrigger="matAutocompleteTrigger"
[formControl]="contactCtrl"
[matAutocomplete]="auto"
[matChipInputFor]="chipList"
(blur)="contactCtrl.setValue(''); validatorInput.value='';"
(click)="contactCtrl.setValue(''); validatorInput.value=''; operationTrigger.openPanel()">
The trick is
Always clear your html input and your (shared) formControl with an empty and not null value each time the blur and click events occur.
Do NOT do this 'clear' on the input focus event. (Because when you delete the last chip, the input is auto-focus and you will have the famous Expression has changed after it was checked.
Call operationTrigger.openPanel(); when the user click on the input
Setting contactCtrl.setValue(''); allows your autocomplete panel to be automatically opened when you call operationTrigger.openPanel()
Setting validatorInput.value=''; is just a way to properly sync your formControl with the html input to ensure a good UX/UI behavior.
Inside my formArray, the formControl is the same for all the inputs but it does not matter since the user can only manipulate one input at a given time
Since you didn't post your code and you mention the example on the material site I'm going to do it as a fork of the stackblitz example they have on their site.
But this will allow you to open the autocomplete panel again despite having had the cursor there and choosing an option previously.
// Using MatAutocompleteTrigger will give you access to the API that will allow you to
// to open the panel or keep it open
...
#ViewChild(MatAutocompleteTrigger, {static: false}) trigger: MatAutocompleteTrigger;
...
ngAfterViewInit() {
fromEvent(this.fruitInput.nativeElement, 'click')
.pipe(
tap(() => {
this.trigger.openPanel()
})
).subscribe()
}
Link to the full stackblitz:
https://stackblitz.com/edit/angular-sb38ig
i've just started web programming and have a problem with removing a tap listener added with polymer.
My component 'my-button' has a tap listener:
listeners: {
tap: '_onTap'
}
my-buttons can be added to a my-button-group.
<my-button-group>
<my-button></my-button>
<my-button></my-button>
...
</my-button-group>
if a button was added to a my-button-group i want to remove the tap listeners of all buttons in the group.
i've tried to iterate over the groups children, but i can't find the listener in the childrens attributes/properties.
thank you
I assume you are iterating over the children with Polymer.dom(group).functions then call node.unlisten() to remove listener (see https://www.polymer-project.org/1.0/docs/api/Polymer.Base and go to the methods and the api. You can use this.unlisten() if you are working within an element, but any reference to the element will work. Remember that the nodes you are working with are "distrubuted" (ie they come from the content) so you will need to use Polymer.dom(mygroup).getDistributedNodes();
I am trying to implement multiple select on ComboBox with check boxes in flex 4.1. By default the combo box closes after every select, is there any way to override that default function?
1) // is there any way to override that default function?
In combobox the open/close of the popupList was handled by DropDownController.as in DropDownListBase.as i hope u can override closeDropDown method to prevent close.But ensure you need to handle the close when click outside the combobox.
override public function closeDropDown(commit:Boolean):void
{
// your logic goes here
// call super if needed to close
//super.closeDropDown(commit);
}
For preventing the default behavior You can also use the below methods on close event (or ItemClick event if it has one)
event.preventDefault();
which Cancels an event's default behavior if that behavior can be canceled.
event.stopPropagation();
which Prevents processing of any event listeners in nodes subsequent to the current node in the event flow.
There are lot of flex example out there for combobox with checkbox itemrenderer before u post any question in stackOverflow do a Google search.
I hope this will help you
https://code.google.com/p/combocheck/source/browse/#svn%2Ftrunk
http://www.flexicious.com/home/FlexMultiSelectComboBox