combobox set seletectedindex at design time

R

Rick

I have a combobox on a WinForm with DropDownStyle = DropDownList.

I don't see any way to set the SelectedIndex of this control at design time.
Do I have to do this in code on Form load?

Rick
 
P

Phill W.

Rick said:
I have a combobox on a WinForm with DropDownStyle = DropDownList.

I don't see any way to set the SelectedIndex of this control at design time.
Do I have to do this in code on Form load?

Rightly or wrongly, I do this as part of the Constructor (Sub New)

This is the start of the "never to be edited" code createdby the Forms
Designer:

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
InitialiseFields() ' <=== Only add this one line

End Sub

.. . .

Private Sub InitialiseFields()

Me.ComboBox1.SelectedIndex = 0

End Sub

This seems to survive the Forms Designer's nasty tendency to trash
anything that it doesn't like the look of in its "generated code"
Region, allowing you to "extend" the Constructor safely.

HTH,
Phill W.
 
R

RobinS

No, there's no way to set it at design time. Just stick it in the
Form Load routine.

Robin S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top