Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i make a combo box like this
combobox DropDownList
0 = 246mb
1 = 512mb
2 = 2gb
3 = 4gb

i want to do...
and when i start app 1 (512mb) is preselected
i prefere to do this in form1_load.. help

*this is optiona,,, only if you know: i can make the combobox to remember my last selected item ? and start with them selected ? TNX i wait for the best help'er !
Posted
Updated 26-Nov-11 7:52am
v2
Comments
LanFanNinja 26-Nov-11 16:15pm    
Check my solution

1 solution

If you want to select only a specific item at start up use this code
VB
ComboBox1.SelectedIndex = 0 'would set it to 246mb, 1 would set to 512mb, etc.


To make you app remember which item was select when it closed and reselect it on start up you will need to first create a property in your Settings.vb file

1) Right click your project in the solution explorer (or double click on the "My Project" folder in solution explorer)
2) Click on properties
3) In the tab window that opens click on the settings tab to the left
4) Add a new property called ComboSelectedIndex and set its type to Integer

the use this code
VB
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    ComboBox1.SelectedIndex = My.Settings.ComboSelectedIndex
End Sub

Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    My.Settings.ComboSelectedIndex = ComboBox1.SelectedIndex
    My.Settings.Save()
End Sub


If you need more explanation let me know and I will try to help.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900