C # The ComboBox implementation cannot be input, and the drop-down box text has a value

Source: Internet
Author: User

The drop-down box has the DropDownStyle attribute. If you select the DropDownStyle type as the DropDownList, you can only select the drop-down box and cannot enter it. However, the drop-down box does not have a default value. It does not work even if you enter the default value in the Text attribute. It must be modified in the file (XX. Designer. cs.
This is not modified:
This. ComboBox1.Cursor = System. Windows. Forms. Cursors. Default;
This. ComboBox1.DropDownStyle = System. Windows. Forms. ComboBoxStyle. DropDownList;
This. comboBox1.Font = new System. drawing. font ("Arial", 9F, System. drawing. fontStyle. regular, System. drawing. graphicsUnit. point, (byte) (0 )));
This. ComboBox1.FormattingEnabled = true;
This. ComboBox1.Items. AddRange (new object [] {
"1 ",
"2 ",
"3 "});
This. ComboBox1.Location = new System. Drawing. Point (138,124 );
This. ComboBox1.Name = "ComboBox1 ";
This. ComboBox1.Size = new System. Drawing. Size (150, 23 );
This. ComboBox1.TabIndex = 15;
The bold line of code is a drop-down box that can only select settings that cannot be entered.
Add a default value before that line of code. Modify as follows:
This. ComboBox1.Cursor = System. Windows. Forms. Cursors. Default;
This. comboBox1.Font = new System. drawing. font ("Arial", 9F, System. drawing. fontStyle. regular, System. drawing. graphicsUnit. point, (byte) (0 )));
This. ComboBox1.FormattingEnabled = true;
This. ComboBox1.Items. AddRange (new object [] {
"1 ",
"2 ",
"3 "});
This. ComboBox1.Text = this. ComboBox1.Items [0]. ToString ();
This. ComboBox1.DropDownStyle = System. Windows. Forms. ComboBoxStyle. DropDownList;
This. ComboBox1.Location = new System. Drawing. Point (138,124 );
This. ComboBox1.Name = "ComboBox1 ";
This. ComboBox1.Size = new System. Drawing. Size (150, 23 );
This. ComboBox1.TabIndex = 15;
If the first line is bold
This. ComboBox1.Text = "Default Value ";
The default value is the same as that directly entered in the attribute, and will be automatically deleted.
Note: The first line of the bold statement should be written in
This. ComboBox1.Items. AddRange (new object [] {
"1 ",
"2 ",
"3 "});
Statement. The preceding statement can be set in Items attributes.
After all the above are written, the results will be achieved, but the effects will be changed in some components (even if they are not associated with the drop-down box), the entire file will be restructured, the modified statements will be restored, and nothing is changed. In other words, every time a component is modified, the above action must be done again.
My method is to write all the values assigned by the default value in another method written by myself, and then call this method after initialization.
 

Related Article

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.