The ListView and right-click menus are for example:
To implement the functionality is:
1, when the user status is "active", change the user state to "active" disabled, reverse.
2, and only the real user status is "inactive", "Delete learner user" is the available status.
Features are very easy to solve, such as the following:
"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 Change 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 inferring the value of the fourth item in the currently selected row in the ListView.
Note: It is necessary to determine the availability of two items, otherwise it will appear that both 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 the fact is very easy. )
All right. User state inference to delete a learner user this is simple.
Assume that the column name menu is not selected or selected. Cancel the popup private void Cmsrightmenu_opening (object sender, CancelEventArgs e) of the right-click menu { //infer if the item is selected, otherwise the right-click menu does not pop up if (lvstudent.selecteditems.count>0) { //based on user state to disable deletion of 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 for the right-click menu. First infer whether an item is selected, otherwise the right-click menu does not pop up. Disable the delete option based on the user state, otherwise it cannot be disabled (else cannot be saved). The consequences are the same as they were previously said).
The final effect is for example with:
This is the end of today's little experience sharing.
People who have just started to study please give us a lot of advise.
END.
The options for the submenu of the right-click menu of the C # WinForm ListView are disabled as appropriate