I think the reason it is zero is because of Late Binding. I have already
attempted to use the SelectedIndex property which fails because the Items are
not initialised.
Incidently I have also tried to use this.SelectedValue = "GBR" which also
fails for the same reason.
The combobox is initialised correctly as it works as advertised once it is
displayed, it is merely setting the default value which has become a
challenge.
I have also tried adding each of the properties using this.Items.Add()
within the constructor but this causes problems when using this as a
component within the IDE as values can be duplicated during editing.
I have attempted to use the bindmanager but the bindcontext for this
datasource appears not to exist until after the constructor has been run.
Would appreciate any assistance or code samples.
> How can the item count be zero, when you have added items to the combo?
> Can you post some more code?
[quoted text clipped - 28 lines]
> > I then need to set the default to the United Kingdom but at this point item
> > count is zero, How do I set the default value on initialisation.
Joey Calisay - 16 Sep 2004 16:22 GMT
Where are you setting the default value of the combo? You should set it on
the Load event of the form.
> I think the reason it is zero is because of Late Binding. I have already
> attempted to use the SelectedIndex property which fails because the Items are
[quoted text clipped - 48 lines]
> > > I then need to set the default to the United Kingdom but at this point item
> > > count is zero, How do I set the default value on initialisation.
BobM - 16 Sep 2004 16:53 GMT
I have a generic address usercontrol. I have overriden the OnLoad function
which saves me putting this on every form.
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
if( this.Country.SelectedIndex<0)
{
this.Country.SelectedValue = "GBR";
}
}
> Where are you setting the default value of the combo? You should set it on
> the Load event of the form.
[quoted text clipped - 56 lines]
> item
> > > > count is zero, How do I set the default value on initialisation.
BobM - 16 Sep 2004 16:29 GMT
I have managed to set the default value external to the ComboBox by setting
the SelectedValue in a custom control which includes the ComboBox below
however this is only a short term solution and I would still like to set the
default value within the original combobox. Any suggestions?
> I think the reason it is zero is because of Late Binding. I have already
> attempted to use the SelectedIndex property which fails because the Items are
[quoted text clipped - 48 lines]
> > > I then need to set the default to the United Kingdom but at this point item
> > > count is zero, How do I set the default value on initialisation.