Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Databind combo box with our showing first row of data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
moondaddy - 22 Sep 2004 04:39 GMT
I'm writing an app in vb.net 1.1 and all of my forms use a combo box to
navigate to different records.  when the form loads I databind a dataset
table to the combo box.  However, the form is opening up to a blank - new
record and I don't want any text showing in the text area of the combo box.
I want the combo box's text area to show nothing until the user selects
something from its list.  Below is the code used to populate the combo and
some remmed lines where it tried to force the combo to have nothing
selected.  Can someone please advise me on how to do this?

Thanks!

Private Sub cmbGoToRowSource(ByRef tb As
wsContactMangaer.dsContactMngr.tbAddressListByCustDataTable)
   Try
       Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
       Me.cmbGoTo.DataSource = tb
       Me.cmbGoTo.DisplayMember = "Name"
       Me.cmbGoTo.ValueMember = "ID"
       'Me.cmbGoTo.SelectedIndex = -1  'These 3 lines still left text in
the combo box text area
       'Me.cmbGoTo.Text = ""
       'Me.cmbGoTo.SelectedText = ""

   Catch ex As Exception
       ErrLog(ex)
   Finally
       Cursor.Current = System.Windows.Forms.Cursors.Default
   End Try
End Sub

Signature

moondaddy@nospam.com

Tim Wilson - 22 Sep 2004 05:52 GMT
In order to clear a databound ComboBox, try setting the SelectedIndex to
"-1" twice.
http://support.microsoft.com/default.aspx?scid=kb;en-us;327244

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>

> I'm writing an app in vb.net 1.1 and all of my forms use a combo box to
> navigate to different records.  when the form loads I databind a dataset
[quoted text clipped - 25 lines]
>     End Try
> End Sub
moondaddy - 22 Sep 2004 15:42 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.