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