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 / March 2006

Tip: Looking for answers? Try searching our database.

Hell = ComboBox databinding at design time

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David McClelland - 17 Mar 2006 01:55 GMT
Hi there,

I'm using VS.NET 2003 / VB.NET and binding a strongly-typed dataset (Fln1)
to my combobox.  The strongly-typed dataset is displayed in the component
"tray" on my form, so at design time, I can configure the combobox to bind to
Fln1, and the Windows Forms Designer generates the following code:

       Me.ComboBox1.DisplayMember = "LOCTYPE.LocationType"
       Me.ComboBox1.ValueMember = "LOCTYPE.LocationType"
       Me.ComboBox1.DataSource = Me.Fln1
       Me.ComboBox1.DataBindings.Add(New
System.Windows.Forms.Binding("SelectedValue", Me.Fln1, "FLN.LocationType"))

So this looks right...   I thought!

In the Form_Load event of my Form, I fill up the dataset (Fln1) with the
data needed, and the form displays itself - but the combobox is not bound
correctly:  it is positioned at the first item in the combobox, not the
correct one for the dataset contents!

BUT, if I take those EXACT same lines of code and move them from the "
Windows Form Designer generated code " section to the Form_Load event, the
combobox functions correctly - the right element in the Combobox is selected!

Aaaarrrgghhhh!?!?!?!  Why?  I would like to be able to configure this at
design-time, not waiting until run-time, does anyone have any ideas what I'm
doing wrong?

- David McClelland
Truong Hong Thi - 17 Mar 2006 09:08 GMT
Maybe you need to fill the dataset earlier; let's move it to the
constructor, before the call of InitializeComponent and see if it works.
David McClelland - 17 Mar 2006 16:53 GMT
Thank you so much for the suggestion; however, when I attempt to fill the
dataset before the call to InitializeComponent() the dataset has not be
instantiated yet, since this line is inside InitializeComponent():

Me.Fln1 = New WindowsApplication4.FLN

I tried moving this line out of InitializeComponent(), but then the Forms
designer got all upset saying "The variable 'Fln1' is either undeclared or
was never assigned."

So...   I undid that change, and then I tried filling the dataset in the
constructor right after the call to InitializeComponent() - and it worked!

Thanks for pointing me down the right track!

- David

> Maybe you need to fill the dataset earlier; let's move it to the
> constructor, before the call of InitializeComponent and see if it works.

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.