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

Source: Internet
Author: User

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

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.