- 1). Open Visual Studio 2010 by clicking on its program icon. When it loads, select "File/New/Project" and click "Visual C#/Windows Forms Application." A new Windows Form Application project is created, and a blank Windows Form appears in the main editor window.
- 2). Locate the "Toolbox" panel located on either side of the main editor window. This box features lists of items that can be used to build a graphical user interface. Find the one labeled "CheckBox."
- 3). Click and drag the CheckBox from the "Toolbox" panel onto the form. A check box will appear on the form.
- 4). Locate the item named "TextBox" from the "Toolbox" panel. Drag and drop this item like what you did with the "CheckBox".
- 5). Double-click the "CheckBox" to open the source code page associated with the check box.
- 6). Find the source code that says "public partial class Form1 : Form." Below this statement, write the following list declaration:
static List<string> myList = new List<string>(); - 7). Find the source code that says "public Form1()." Below this statement, write the following statements to add some items to the list:
myList.Add("A");
myList.Add("B");
myList.Add("C");
myList.Add("D");
myList.Add("E"); - 8). Locate the text labeled "checkBox1_CheckedChanged." This code executes whenever the check box is clicked on or off.
- 9). Loop through every item in the list you want to filter. Write a "foreach" loop to accomplish this. Write the following right below the "CheckBox" code block that appeared when you double clicked it.
foreach (var letter in myList)
{} - 10
Filter the list based on some criteria. For example, to filter out all the letters "A," write the following between the curly brackets of the "foreach" loop"
if (letter != "A")
{} - 11
Add the filtered text to the "TextBox" item you created on the form. To do this, write the following within the curly brackets of the "if" statement:
textBox1.Text += letter; - 12
Execute the program by pressing the green "Play" button. The program will display a check box. Click it once to filter the list. The text box now displays the letters "BCDE."
next post