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
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