
Signature
Tim Wilson
.Net Compact Framework MVP
<Feedback>
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
</Feedback>
Thanks. I found that I only needed to set the selectedindex to "-1" one
time, but after the form was finished loading and set to visible.
aprearantly setting the selected index to -1 doesn't work if the form hasn't
been set to visible yet. I figured this out be adding a test button and
setting the index to -1 in the button's click event. This is unfortunate
because all of my form's initialization code is called from the new sub
where I pass in parameters to tell the form what data to populate with, etc.
like this:
private frm as Myform
'========= now from a method
frm = new Myform (PK, flag1, flag2)
frm.visible = true
so I tried a hack work around by executing the code:
Me.cmbGoTo.SelectedIndex = -1
from the forms' visiblechanged event so when the form finally becomes
visible the combo boxes' text is cleared. this work, but I wouldn't want to
use it as a standard way of doing things because what happens if I need to
change a form's visible property? the dropdown boxes' indexes will all
change and cause havoc.
can anyone think of a better solution? it would be great if there was an
event such as form finished loading event if selected index = -1 would work
in such an event.
any good ideas?
Thanks again.

Signature
moondaddy@nospam.com
> In order to clear a databound ComboBox, try setting the SelectedIndex to
> "-1" twice.
[quoted text clipped - 30 lines]
> > End Try
> > End Sub
Tim Wilson - 22 Sep 2004 16:46 GMT
Yeah, I've run into this problem before as well. It's kind of a pain. One
way to do this is to override the forms OnActivated method (or hook the
forms Activated event) and perform any one time form initialization there.
But you'll need to use a flag to ensure that the code is called only once.
private bool initialized = false;
protected override void OnActivated (System.EventArgs e)
{
if (!initialized)
{
initialized = true;
this.comboBox1.SelectedIndex = -1;
}
base.OnActivated(e);
}

Signature
Tim Wilson
.Net Compact Framework MVP
<Feedback>
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
</Feedback>
> Thanks. I found that I only needed to set the selectedindex to "-1" one
> time, but after the form was finished loading and set to visible.
[quoted text clipped - 63 lines]
> > > End Try
> > > End Sub
moondaddy - 29 Sep 2004 04:07 GMT
Thanks I thought about doing something like this, but then thought that I
just didn't know how to do it correctly. maybe it will be better in 2.0

Signature
moondaddy@nospam.com
> Yeah, I've run into this problem before as well. It's kind of a pain. One
> way to do this is to override the forms OnActivated method (or hook the
[quoted text clipped - 87 lines]
> > > > End Try
> > > > End Sub