
For the rest of this tutorial I'll show using it without Data Sources, For simpler display needs you may find a plain ListView more suitable. data from a database) and without (ie data that you add programmatically). It only enables the Remove Item menu entry when there is a selected row.Ī DataGridView is both the most complex and the most useful component provided for free with C#. Private void btnAdd_Click(object sender, System.EventArgs e) I've double clicked the add button to create an event btnAdd_Click() event handler and added this event line. In example 2, I've renamed the ComboBox to combo, changed the combo DropDownStyle back to DropDown so it can be edited and added an Add button called btnAdd. On the next page : Winforms ComboBoxes Continued Why? Because at design time you must grab the lower stretch handle and make the whole control taller. If you set the DropDownStyle property for the combo to Simple and run the program you'll get nothing. Find InitializeComponent() and add that line immediately after this. You have to view the code for the form (in the Solution Explorer, right click on From1.cs and click View Code. How do we select a number to start with? Well it's not a property you can set at design time but adding this line will do that.Īdd that line in the Form1() constructor. You can select one of the numbers but it always opens blank. Now there's no text and it's not editable. Find the DropDownStyle property and change DropDown to DropDownList.(It's a Combo!). It's annoying that when it opens it says comboBox1 and you can edit it. Feel Free to set it to 20 or 3 and then run it to see what it does. When you run it you'll only see 8 because that's the default value of MaxDropDownItems.


Now stop the program and add a few more numbers: four, five. You can then type in the strings, compile the program and pull the combo down to see choices. I'm not touching data and binding until a later tutorial.Let's begin with a simple control, a ComboBox.Īt the heart of a Combo is an items collection and the simplest way to populate this is drop a combo on the screen, select properties (if you can't see the properties windows, click View on the top Menu and then Properties Window), find items and click the ellipses button.

In this C# programming tutorial, I'll be concentrating on the advanced controls such as ComboBoxes, Grids, and ListViews and showing you the way you'll most likely use them.
