The options for the submenu of the right-click menu of the C # WinForm ListView are disabled as appropriate

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.