DataSource & DataMember property at custom control.

  • Thread starter Thread starter Alvaro E. Gonzalez V.
  • Start date Start date
A

Alvaro E. Gonzalez V.

Hello!!!


I'm building a control that in a property
assign a Dataset which they are initialized and another property Like
DataMember.

Similar as it happens to the DataSource property of a System.Windows.Forms.ListBox...

That mechanism can be used or as is the best way to do it...


Thanks.
Alvaro.
 
You can use a DataSource and DataMember. Underneath, this creates a
BindingManagerBase as so:

BindingManagerBase myBMB = BindingContext[dataSource, dataMember].

You can then access the data via the BindingManagerBase.

In most cases, you'll find the BindingManagerBase is actually a
CurrencyManager or RelatedCurrencyManager, depending on what exactly you're
binding to.

For more information about CurrencyManager I recommend this page:

http://noiseehc.freeweb.hu/CurrencyManager.html

I've also posted two article on my web site about it. I plan to do more,
just haven't gotten around to it yet:

http://www.petedavis.net/MySite/DynPageView.aspx?pageid=19
http://www.petedavis.net/MySite/DynPageView.aspx?pageid=22

Pete



The BindingContext actually returns a BindingManagerBase object but for a
datasource and
 
Hi,

I use this code:

private System.Windows.Forms.ListBox dropdownsource = new ListBox() ;
public object DataSource{
get {
return this.dropdownsource.DataSource;
}
set{
if (this.dropdownsource.DataSource != value)
this.dropdownsource.DataSource = value;
}
}

I hope that in the properties palete be shown the same way that DataSource ListBox's property

I must any attribute o Wath somethings i must do?



_________________________________________________________________________
Pete said:
You can use a DataSource and DataMember. Underneath, this creates a
BindingManagerBase as so:

BindingManagerBase myBMB = BindingContext[dataSource, dataMember].

You can then access the data via the BindingManagerBase.

In most cases, you'll find the BindingManagerBase is actually a
CurrencyManager or RelatedCurrencyManager, depending on what exactly you're
binding to.

For more information about CurrencyManager I recommend this page:

http://noiseehc.freeweb.hu/CurrencyManager.html

I've also posted two article on my web site about it. I plan to do more,
just haven't gotten around to it yet:

http://www.petedavis.net/MySite/DynPageView.aspx?pageid=19
http://www.petedavis.net/MySite/DynPageView.aspx?pageid=22

Pete



The BindingContext actually returns a BindingManagerBase object but for a
datasource and
Hello!!!


I'm building a control that in a property
assign a Dataset which they are initialized and another property Like
DataMember.

Similar as it happens to the DataSource property of a
System.Windows.Forms.ListBox...

That mechanism can be used or as is the best way to do it...


Thanks.
Alvaro.
 
I found the solution :
private System.Windows.Forms.ListBox dropdownsource = new ListBox() ;

[RefreshProperties(RefreshProperties.Repaint)]
[TypeConverter("System.Windows.Forms.Design.DataSourceConverter")]
public object DataSource{
get {
return this.dropdownsource.DataSource;
}
set{
if (this.dropdownsource.DataSource != value)
this.dropdownsource.DataSource = value;
}
}

[TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter")]
[Editor("System.Windows.Forms.Design.DataMemberFieldEditor",typeof(System.Drawing.Design.UITypeEditor))]
[DefaultValue("")]
public string DisplayMember{
get {
return this.dropdownsource.DisplayMember;
}
set{
if (this.dropdownsource.DisplayMember != value)
this.dropdownsource.DisplayMember = value;
}
}


[CLSCompliant(false)]
[TypeConverter("System.Windows.Forms.Design.ValueMemberFieldConverter")]

[Editor("System.Windows.Forms.Design.DataMemberFieldEditor",typeof(System.Drawing.Design.UITypeEditor))]
[DefaultValue("")]
public string ValueMember{
get {
return this.dropdownsource.ValueMember;
}
set{
if (this.dropdownsource.ValueMember != value)
this.dropdownsource.ValueMember = value;
}
}


___________________________________________________________________________
Alvaro said:
Hi,

I use this code:

private System.Windows.Forms.ListBox dropdownsource = new ListBox() ;
public object DataSource{
get {
return this.dropdownsource.DataSource;
}
set{
if (this.dropdownsource.DataSource != value)
this.dropdownsource.DataSource = value;
}
}

I hope that in the properties palete be shown the same way that
DataSource ListBox's property

I must any attribute o Wath somethings i must do?



_________________________________________________________________________
Pete said:
You can use a DataSource and DataMember. Underneath, this creates a
BindingManagerBase as so:

BindingManagerBase myBMB = BindingContext[dataSource, dataMember].

You can then access the data via the BindingManagerBase.

In most cases, you'll find the BindingManagerBase is actually a
CurrencyManager or RelatedCurrencyManager, depending on what exactly
you're binding to.

For more information about CurrencyManager I recommend this page:

http://noiseehc.freeweb.hu/CurrencyManager.html

I've also posted two article on my web site about it. I plan to do
more, just haven't gotten around to it yet:

http://www.petedavis.net/MySite/DynPageView.aspx?pageid=19
http://www.petedavis.net/MySite/DynPageView.aspx?pageid=22

Pete



The BindingContext actually returns a BindingManagerBase object but
for a datasource and
Hello!!!


I'm building a control that in a property
assign a Dataset which they are initialized and another property Like
DataMember.

Similar as it happens to the DataSource property of a
System.Windows.Forms.ListBox...

That mechanism can be used or as is the best way to do it...


Thanks.
Alvaro.
 
Back
Top