| |

VerySource

 Forgot password?
 Register
Search
View: 769|Reply: 5

How to set comboBox in winform to the first Item as soon as the page starts

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-10 22:00:01
| Show all posts |Read mode
How to set comboBox in winform to the first Item as soon as the page is launched,
Cannot be set to the first item in the form's Load, as that will trigger SelectedIndexChanged.
I want to set the index to 0 when the page loads
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-5 18:45:01
| Show all posts
comboBox.SelectIndex = 0
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-4-5 20:45:01
| Show all posts
It is to write the following code in the Load event of Form:

if (comboBox.Item.Count> 0)
{
    comboBox.SelectedIndex = 0;
}
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-6 02:45:01
| Show all posts
InitializeComponent
this.comboBox1.SelectedIndexChanged + = new System.EventHandler (this.comboBox1_SelectedIndexChanged); remove
statement:
private EventHandler selIndexChanged = null;
Add under winform load:
selIndexChanged + = new new System.EventHandler (this.comboBox1_SelectedIndexChanged);
comboBox.SelectIndex = 0;
comboBox1.SelectedIndexChanged + = selIndexChanged;
Reply

Use magic Report

0

Threads

27

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-4-6 14:00:02
| Show all posts
Positive solution upstairs.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-21 00:15:01
| Show all posts
Remove the event first, set the item, and restore the event
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list