ComboBox implementations in C # can only choose not to enter, and there are default values in the drop-down box.

Source: Internet
Author: User

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.

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.