Drop-down box has dropdownstyle this property, the DropDownStyle type is selected as DropDownList, the drop-down box can only select cannot be entered. However, the drop-down box at this time does not have a default value, and it does not work even if you enter a default value in the Text property. It's going to be in (a. Designer.cs) file.
This is not modified:
This. Nametemplatebox.cursor = System.Windows.Forms.Cursors.Default;
This . Nametemplatebox.dropdownstyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
This. Nametemplatebox.font = new System.Drawing.Font ("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (0)));
This. Nametemplatebox.formattingenabled = true;
This. NameTemplateBox.Items.AddRange (new object[] {
"--Choose the template--",
"First",
"First,last",
"First,middle,last"});
This. Nametemplatebox.location = new System.Drawing.Point (138, 124);
This. Nametemplatebox.name = "Nametemplatebox";
This. Nametemplatebox.size = new System.Drawing.Size (150, 23);
This. Nametemplatebox.tabindex = 15;
The bold line of code is that the drop-down box can only select settings that cannot be entered.
To add a default value setting before that line of code. Modify the following:
This. Nametemplatebox.cursor = System.Windows.Forms.Cursors.Default;
This. Nametemplatebox.font = new System.Drawing.Font ("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (0)));
This. Nametemplatebox.formattingenabled = true;
This. NameTemplateBox.Items.AddRange (new object[] {
"--Choose the template--",
"First",
"First,last",
"First,middle,last"});
This . Nametemplatebox.text = this. Nametemplatebox.items[0]. ToString ();
This . Nametemplatebox.dropdownstyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
This. Nametemplatebox.location = new System.Drawing.Point (138, 124);
This. Nametemplatebox.name = "Nametemplatebox";
This. Nametemplatebox.size = new System.Drawing.Size (150, 23);
This. Nametemplatebox.tabindex = 15;
If the first line is bold, change to
This. Nametemplatebox.text = "Default value";
is automatically deleted, as is the default value entered directly in the property.
Note: The first row of bold statements is written in
This. NameTemplateBox.Items.AddRange (new object[] {
"--Choose the template--",
"First",
"First,last",
"First,middle,last"});
After the statement. The above statement can be set in the properties of the items.
After the above is written, it will achieve the effect, but the effect in some components have changed (even if not with the drop-down box is related), the entire file will be refactored, the modified statements inside will be restored to, equal to nothing changed. In other words, each time the component is modified, it is necessary to do the above action again ...
my method is to write the default values in the other way, and then call this method after initializing the build.
ComboBox implementations in C # can only choose not to enter, and there are default values in the drop-down box.