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 Data Binding / January 2007

Tip: Looking for answers? Try searching our database.

BindingContext and components

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard - 15 Jan 2007 13:29 GMT
Hello,
I'm trying to write a component that has a DataSource and DataMember
property much like the DataGridView. I want to use the CurrencyManager
so I need to access the BindingContext of the form. But how can I do
this? If I wrote a control, I could just do
Parent.BindingContext[dataSource], but for a Component, there is not
parent. Am I overlooking something? I also tried going via the
IComponent.Site, but it seems the container is a separate class, not the
form itself. How do I get to the container form when using a component?
Thank you
/R
RobinS - 15 Jan 2007 18:56 GMT
You might check out Brian Noyes' book on data binding.
He explains how to create your own components and support
data binding for them. I haven't done that, but made
a note where I could find the information if I needed it.

Robin S.
-----------------------------------------------
> Hello,
> I'm trying to write a component that has a DataSource and DataMember
[quoted text clipped - 8 lines]
> Thank you
> /R
Bart Mermuys - 15 Jan 2007 23:54 GMT
Hi,

> Hello,
> I'm trying to write a component that has a DataSource and DataMember
> property much like the DataGridView. I want to use the CurrencyManager so
> I need to access the BindingContext of the form. But how can I do this? If
> I wrote a control, I could just do Parent.BindingContext[dataSource],

If you wrote a Control then you would use the Control's BindingContext
property, if it hasn't been set it would get the parents one.

> but for a Component, there is not parent. Am I overlooking something? I
> also tried going via the IComponent.Site, but it seems the container is a
> separate class, not the form itself.

Yes the Container is seperated from the Form, and i don't think you can
access the Form from a Component at runtime.   Keep in mind that Component
could be used without a Form.

I did a quick google search and found something interesting, some code which
makes the designer write code to associate the Component with current
Form/UserControl.
http://groups.google.be/group/microsoft.public.dotnet.framework.windowsforms/bro
wse_thread/thread/9e44c3983e0e0c76/14ae6e6eb98cb7a0?lnk=st&q=%2B%22form+from+com
ponent&rnum=1&hl=nl#14ae6e6eb98cb7a0

(There was a typo, so i put working code at the bottom)

Having said this, i'm not quite sure if it's a good idea to assiociate a
Component with a Form or UserControl ... AFAIK non of the standard
Components do this.

You might also want to ask this question in a broader ng, like
dotnet.framework since it's not just a DataBinding problem.

HTH,
Greetings

public class SomeComponent : Component
{
private Control hostControl;

// ............

public Control HostControl
{
  get { return hostControl; }
  set { hostControl = value; }
}

public override ISite Site
{
get { return base.Site; }
set
{
  base.Site = value;
  IDesignerHost h =
(IDesignerHost)value.GetService(typeof(IDesignerHost) );
  this.HostControl = (Control)h.RootComponent;
 }
}
}

> How do I get to the container form when using a component?
> Thank you
> /R

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.