Comboxbox controls, Checklistbox controls, and ListBox controls are developed together

Source: Internet
Author: User

First step: Create a WinForm form application and lay out the layout as shown.

Step two: Set properties for Comboxbox controls, Checklistbox controls, and ListBox controls and Button controls

Step three: Declare two private arrays in the form class in your code.

Private string[] Names;private string[] nums;

Fourth step: Initialize the array in the form class and do a preparatory work.

private void Form1_load_1 (object sender, EventArgs e)        {            names = new string[] {"Jason", "Jack", "Jay", "Baby"};
   nums = new string[] {"12345", "21345", "32145", "42135"};            THIS.CHECKEDLISTBOX1.ITEMS.ADD (names);            This.comboBox1.SelectedIndex = 0;        }

Fifth step: Add a Trigger event for button buttons.

private void Button1_Click (object sender, EventArgs e)        {            //count is used to get the number of selected in the CheckedListBox            int Count = This.checkedListBox1.CheckedItems.Count;            if (This.checkedListBox1.Items.Count = = 0) return;            If CheckedListBox one is not selected if            (This.checkedListBox1.SelectedIndex = =-1)            {                MessageBox.Show (" Please select the item to add in the Checklistbox ");                return;            }            Adds the selected item to the listbox for            (int i = 0; i < Count; i++)            {                This.listBox1.Items.Add ( This.checkedlistbox1.checkeditems[i]);            }            MessageBox.Show ("The selected item has been moved to the ListBox");        

Sixth step: Add a Trigger event for the ComboBox control and put the array into CheckedListBox when the value in the control is a name.

<summary>////        This method is when a field is selected in the ComboBox and the selection for this field is displayed in Checklistbox///        </summary>//        <param name= "Sender" ></param>//        <param name= "E" ></param>        private void combobox1_ SelectedIndexChanged (object sender, EventArgs e)        {            combobox cb = (combobox) sender;            Switch (CB. SelectedIndex)            {case                0:                    this.checkedListBox1.Items.Clear ();                    This.checkedListBox1.Items.AddRange (names);                    break;                Case 1:                    this.checkedListBox1.Items.Clear ();                    This.checkedListBox1.Items.AddRange (nums);                    break;            }            This.listBox1.Items.Clear ();        }

Seventh step: Run the process.

① Start Interface:

② when you select a value in CheckedListBox and click Submit message:

③ Select the number and select the value in CheckedListBox and click Submit message:

Eighth step: you are done.

Comboxbox controls, Checklistbox controls, and ListBox controls are developed together

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.