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

Tip: Looking for answers? Try searching our database.

Binding list problem with listbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 23 Jun 2006 17:25 GMT
I have created a Component called a BOConnector that implements IBindingList
so it can provide access to a list of business objects to be bound to
controls.

At design time there is no live list of objects so BOConnector creates an
internal list of one object.  It needs one object because when you bind to a
grid etc at design time it needs to get a list of properties to make the
columns.

My BOConnector works just fine with grids and simple controls like edit
boxes but I have a problem with the ListBox and ComboBox.

When I connect the BOConnector to the ListBox.DataSource it seems to create
a copy of the internal business object and try to save it into its
ListBox.Items in the form definition.  I seem to see what is going on here,
it is taking a copy of the data and loading it into its Items.  But why is
it doing this at design time?  And the complex nature of my business object
means this messes up the form totally.

My first thought is to create a descendant of the ListBox and ComboBox and
make sure it does not copy items from the DataSource to the Items list at
design time.

Has anyone got any ideas?

Signature

Andrew Cutforth - AJC Software - www.ajcsoft.com
The best folder synchronize and directory compare tool available.
AJC Active Backup instantly archives every file you edit giving you
unlimited undo and automatic revision control.  Never lose your data again.

Kevin Spencer - 23 Jun 2006 18:57 GMT
Hi Andrew,

Yes, it's possible to prevent certain code from being executed at
Design-time. The reason for this is that the Controls need to be painted at
Design time, and some logic may be involved in the process. This is a very
simple explanation of a fairly complex topic, so I'll finish with a link to
the full reference for you.

There are certain methods that automatically execute at Design-time, such as
Constructors, InitializeComponent, and OnLoad. There are also Designers that
are involved in the Design-time code execution, and attributes as well.
Fortunately, all of this is available to us, the developers.

There is one easy way to prevent code from executing at Design time,
however. Enclose it in an "if" block:

if (!DesignMode)
{
   //........
}

Fore more details and all kinds of stuff you can do with Designer classes
and attributes, see:

http://msdn2.microsoft.com/en-us/library/37899azc.aspx

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

I recycle.
I send everything back to the planet it came from.

>I have created a Component called a BOConnector that implements
>IBindingList
[quoted text clipped - 25 lines]
>
> Has anyone got any ideas?
Andrew - 24 Jun 2006 21:09 GMT
Thanks for your answer Kevin, but I know all about DesignMode etc.  My
question was really about why these controls are behaving is such a way with
data binding and is the only solution override this behaviour.

Signature

Andrew Cutforth - AJC Software - www.ajcsoft.com
The best folder synchronize and directory compare tool available.
AJC Active Backup instantly archives every file you edit giving you
unlimited undo and automatic revision control.  Never lose your data again.

> Hi Andrew,
>
[quoted text clipped - 53 lines]
>>
>> Has anyone got any ideas?

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.