ListView and right-click menus such as:
To implement the functionality is:
1, when the user status is "active", modify the user state to "active" disabled, reverse.
2. "Delete Learner user" is available only if the user status is "inactive".
The function is simple and the solution is as follows:
"Answers"
Depending on the data ' state ' of the row, which item of the right-click menu is displayed , private void Tsmiupdate_dropdownopening (object sender, EventArgs e) { if ( Lvstudent.selecteditems[0]. SUBITEMS[3]. Text = = "Active") {tsmiinactive.enabled = true; tsmiactive.enabled = false;} else {tsmiinactive.enabled = false; tsmiactive.enabled = true;} }
Select the right-click menu that is bound to the ListView, and then select Modify user status to pop up the submenu to find its dropdownopening (as the name implies: Occurs when dropdown is opening),
It then determines whether to disable its downlevel pop-up menu by judging the value of the fourth item in the currently selected row in the ListView.
Note: The availability of the two items must be determined, otherwise the two are disabled when converted to inactive and then converted.
(This listview is set to select a positive row instead of a cell.) In fact, the main thing is sometimes do not know what time to trigger, figured out is actually very simple. )
OK, according to the user state to determine the deletion of the learner user this is simple.
If the column Name menu is unchecked or selected, the popup private void Cmsrightmenu_opening (object sender, CancelEventArgs e) of the right-click menu is canceled. Determines whether the item is selected, otherwise does not eject the right-click menu if (lvstudent.selecteditems.count>0) { ///According to the user state to disable the delete learner user if ( Lvstudent.selecteditems[0]. SUBITEMS[3]. Text = = "Activity") {tsmidelete.enabled = false;} else {tsmidelete.enabled = true;} } else {e.cancel = true;} }
Select the opening event of the right-click menu to determine whether an item is selected, otherwise the right-click menu is not popped, and the delete option is disabled according to the user state, otherwise it cannot be used (else cannot be saved, as the consequence is said).
The final effect is as follows:
This is the end of today's little experience sharing.
For beginners, please advise.
END.
The options for the submenu of the right-click menu of the C # WinForm ListView are disabled as appropriate