John500
asked on
Correct way to initialize a ListBox during Form Load
Greetings,
I have a Form and I want to load a ListBox with values as the Form loads. I put my own function at the end of the Form's InitializeComponent() like this:
Private Sub InitializeComponent() ' Form initialization
...
...
Me.PerformLayout()
Me.LoadSiteLocations() 'My vb file code
End Sub
However, if I try to view the Form in the designer it gives me the error seen in the picture below.
If I run the program it runs fine, I just can't view the Form in the designer. If I remove the call to LoadSiteLocations() I can view the designer but obviously the ListBox won't get filled.
Just how should I be calling this method??
Thanks
designer-error.JPG
I have a Form and I want to load a ListBox with values as the Form loads. I put my own function at the end of the Form's InitializeComponent() like this:
Private Sub InitializeComponent() ' Form initialization
...
...
Me.PerformLayout()
Me.LoadSiteLocations() 'My vb file code
End Sub
However, if I try to view the Form in the designer it gives me the error seen in the picture below.
If I run the program it runs fine, I just can't view the Form in the designer. If I remove the call to LoadSiteLocations() I can view the designer but obviously the ListBox won't get filled.
Just how should I be calling this method??
Thanks
designer-error.JPG
ASKER
>> Do you need this method to run during design time
No, I just want the ListBox to be filled by the time the Form is displayed. I don't the user to have to click a button to load the ListBox - I wanted it filled at the start.
No, I just want the ListBox to be filled by the time the Form is displayed. I don't the user to have to click a button to load the ListBox - I wanted it filled at the start.
call it from the Page Load event...
ASKER
How does that work. The 'MyForm.Designer.vb' code doesn't contain the event. Neither does the MyForm.vb code have it.
Should I create it and put it in the MyForm.vb file? What does the Page Load event code look like exactly:
Private Sub Page_Load(?????)
LoadSiteLocations()
End Sub
Thanks!
Should I create it and put it in the MyForm.vb file? What does the Page Load event code look like exactly:
Private Sub Page_Load(?????)
LoadSiteLocations()
End Sub
Thanks!
go to the form designer with the problematic code commented out
and from the designer go to the foms property window
click on the lightning bolt to see the lists of event and double click the load
this will take to you back to your code page with the event already registerd.
place the code there
and from the designer go to the foms property window
click on the lightning bolt to see the lists of event and double click the load
this will take to you back to your code page with the event already registerd.
place the code there
oop...i apologize...you're in the designer files...i was talking about page load on form itself...excuse error...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was the ticket, thanks!
How about taking a look at this question when you get a chance:
https://www.experts-exchange.com/questions/23918782/How-to-set-drop-down-arrow-property-for-VB-ListBox.html
How about taking a look at this question when you get a chance:
https://www.experts-exchange.com/questions/23918782/How-to-set-drop-down-arrow-property-for-VB-ListBox.html
Please read this for some design time fixes and how too's
http://bytes.com/forum/thread386210.html