473,856 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UserControl: Databinding

Hi,

I have a UserControl containing some controls of which one is a ComboBox.
All the InternalControl s are Private and some are allowed to be accessed through Public Methods.
One of the things I would like to do (of course) is set the DataBindings.
Something clearly is wrong with the approach I use, because I can't set the Properties in the Designer, the DataSource-Property appears like 'ReadOnly', there is no "dropdown" with the list from System.Windows. Forms.ListContr ol

Dim _DataSource As Object
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Th e data source for the dropdown list."), Category("Data" )> _
Public Overridable Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Sp ecifies the property of the data source whose content you want to display."), Category("Data" )> _
Public Overridable Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
Me.Internal_UiC omboBox.Display Member = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a DataSet, only a DataSet.DataTab le.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #1
13 5356
I'm just guessing here, so take this for what it's worth; instead of using an object could you try to bind to some IEnumerable or other interface object? That way you know the datasource is supported and the designer know what type(s) of objects to expect. I don't know if IEnumerable is the right interface for you but it will work in this example.

Dim DataSource as IEnumerable

Public Overridable Property DataSource() As IEnumerable
Get
Return _DataSource
End Get
Set(ByVal Value As IEnumerable)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\ Path_to_some_xm l_file\MyFile.x ml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol .DataSource = ds.Tables(0).De faultView
Me.MyUserContro l.DisplayMember = "SomeProper ty"

-- or --

The designer will display all IEnumerable interfaces and allow you to choose a datasource that will work with your object.

I looked up the combo box in the Object browser, it looks like it supports IList, IEnumerable and ICollection. Both IList and ICollection implement IEnumerable.

Hope this helps.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message news:u9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a ComboBox.
All the InternalControl s are Private and some are allowed to be accessed through Public Methods.
One of the things I would like to do (of course) is set the DataBindings.
Something clearly is wrong with the approach I use, because I can't set the Properties in the Designer, the DataSource-Property appears like 'ReadOnly', there is no "dropdown" with the list from System.Windows. Forms.ListContr ol

Dim _DataSource As Object
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Th e data source for the dropdown list."), Category("Data" )> _
Public Overridable Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Sp ecifies the property of the data source whose content you want to display."), Category("Data" )> _
Public Overridable Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
Me.Internal_UiC omboBox.Display Member = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a DataSet, only a DataSet.DataTab le.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #2
Hi Jared,

Thanks for your reply.
This won't do the trick because I want my control to be able to bind to ILists and ICollections. As I want to be able to set the Datasource & the Datamember apart, I can't bind to a DataSource in this case.

I want my bindings set like: (both in the Property-Designer as in Run--Time)

With UC
.DataSource = DataSource (eg DataSet) --> This wont work.
.DataMember = "DataTable"
.DisplayMember = "Column"
.ValueMember = "Column"
End With

Regards,

Michael

"Jared" <VB***********@ email.com> wrote in message news:10******** *****@corp.supe rnews.com...
I'm just guessing here, so take this for what it's worth; instead of using an object could you try to bind to some IEnumerable or other interface object? That way you know the datasource is supported and the designer know what type(s) of objects to expect. I don't know if IEnumerable is the right interface for you but it will work in this example.

Dim DataSource as IEnumerable

Public Overridable Property DataSource() As IEnumerable
Get
Return _DataSource
End Get
Set(ByVal Value As IEnumerable)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\ Path_to_some_xm l_file\MyFile.x ml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol .DataSource = ds.Tables(0).De faultView
Me.MyUserContro l.DisplayMember = "SomeProper ty"

-- or --

The designer will display all IEnumerable interfaces and allow you to choose a datasource that will work with your object.

I looked up the combo box in the Object browser, it looks like it supports IList, IEnumerable and ICollection. Both IList and ICollection implement IEnumerable.

Hope this helps.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message news:u9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a ComboBox.
All the InternalControl s are Private and some are allowed to be accessed through Public Methods.
One of the things I would like to do (of course) is set the DataBindings.
Something clearly is wrong with the approach I use, because I can't set the Properties in the Designer, the DataSource-Property appears like 'ReadOnly', there is no "dropdown" with the list from System.Windows. Forms.ListContr ol

Dim _DataSource As Object
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Th e data source for the dropdown list."), Category("Data" )> _
Public Overridable Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Sp ecifies the property of the data source whose content you want to display."), Category("Data" )> _
Public Overridable Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
Me.Internal_UiC omboBox.Display Member = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a DataSet, only a DataSet.DataTab le.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #3
Michael,
Forgive my ignorance, but, doesn't the designer only support strong types? Now I am curious to see the answer.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi Jared,

Thanks for your reply.
This won't do the trick because I want my control to be able to bind to ILists and ICollections. As I want to be able to set the Datasource & the Datamember apart, I can't bind to a DataSource in this case.

I want my bindings set like: (both in the Property-Designer as in Run--Time)

With UC
.DataSource = DataSource (eg DataSet) --> This wont work.
.DataMember = "DataTable"
.DisplayMember = "Column"
.ValueMember = "Column"
End With

Regards,

Michael

"Jared" <VB***********@ email.com> wrote in message news:10******** *****@corp.supe rnews.com...
I'm just guessing here, so take this for what it's worth; instead of using an object could you try to bind to some IEnumerable or other interface object? That way you know the datasource is supported and the designer know what type(s) of objects to expect. I don't know if IEnumerable is the right interface for you but it will work in this example.

Dim DataSource as IEnumerable

Public Overridable Property DataSource() As IEnumerable
Get
Return _DataSource
End Get
Set(ByVal Value As IEnumerable)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\ Path_to_some_xm l_file\MyFile.x ml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol .DataSource = ds.Tables(0).De faultView
Me.MyUserContro l.DisplayMember = "SomeProper ty"

-- or --

The designer will display all IEnumerable interfaces and allow you to choose a datasource that will work with your object.

I looked up the combo box in the Object browser, it looks like it supports IList, IEnumerable and ICollection. Both IList and ICollection implement IEnumerable.

Hope this helps.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message news:u9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a ComboBox.
All the InternalControl s are Private and some are allowed to be accessed through Public Methods.
One of the things I would like to do (of course) is set the DataBindings.
Something clearly is wrong with the approach I use, because I can't set the Properties in the Designer, the DataSource-Property appears like 'ReadOnly', there is no "dropdown" with the list from System.Windows. Forms.ListContr ol

Dim _DataSource As Object
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Th e data source for the dropdown list."), Category("Data" )> _
Public Overridable Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Sp ecifies the property of the data source whose content you want to display."), Category("Data" )> _
Public Overridable Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
Me.Internal_UiC omboBox.Display Member = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a DataSet, only a DataSet.DataTab le.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #4
>I'm still trying to figure out how to list the DisplayMembers &
ValueMembers
in the Dropdown of the Property-Designer.


<Category("So me Category"),Defa ultValueAttribu te(""),
RefreshProperti es(RefreshPrope rties.Repaint),
Editor(typeof(E xtendedDataGrid .Utilities.Data MemberFieldEdit or),
typeof(System.D rawing.Design.U ITypeEditor))> _
Public Property DisplayMember() as String
'...
End Property

Ernest

"Michael Maes" <mi*****@merlot .com> wrote in message
news:O#******** ******@tk2msftn gp13.phx.gbl...
Hi Jared,

Of course you're right. Maybe I didn't express myself too clear. (which
often happens, so I've added a pic to clarify)
If I declare the Property as an IEnumerable, then I get an imlpicit
TypeConversion Error since a DataSet doesn't implement the IEnumerable
interface.

Bit by bit the puzzle is "coming to pieces" and I've got the DataSource
(Object) & the DataMember-Properties working just fine now (I used a
TypeConverter and a UITypeEditor). I'm still trying to figure out how to
list the DisplayMembers & ValueMembers in the Dropdown of the
Property-Designer.

So basically my issue is one of the IDE. I can set my properties through
code without any problem, but I want a developer to be able to select the
available DataSources, DataMembers and DataColums in a Dropdown......

Regards,

Michael
"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
Michael,
Forgive my ignorance, but, doesn't the designer only support strong
types? Now I am curious to see the answer.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi Jared,

Thanks for your reply.
This won't do the trick because I want my control to be able to bind to
ILists and ICollections. As I want to be able to set the Datasource & the
Datamember apart, I can't bind to a DataSource in this case.

I want my bindings set like: (both in the Property-Designer as in
Run--Time)

With UC
.DataSource = DataSource (eg DataSet) --> This wont work.
.DataMember = "DataTable"
.DisplayMember = "Column"
.ValueMember = "Column"
End With

Regards,

Michael

"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
I'm just guessing here, so take this for what it's worth; instead of
using an object could you try to bind to some IEnumerable or other interface
object? That way you know the datasource is supported and the designer know
what type(s) of objects to expect. I don't know if IEnumerable is the right
interface for you but it will work in this example.

Dim DataSource as IEnumerable

Public Overridable Property DataSource() As IEnumerable
Get
Return _DataSource
End Get
Set(ByVal Value As IEnumerable)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\ Path_to_some_xm l_file\MyFile.x ml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol .DataSource = ds.Tables(0).De faultView
Me.MyUserContro l.DisplayMember = "SomeProper ty"

-- or --

The designer will display all IEnumerable interfaces and allow you to
choose a datasource that will work with your object.

I looked up the combo box in the Object browser, it looks like it
supports IList, IEnumerable and ICollection. Both IList and ICollection
implement IEnumerable.

Hope this helps.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message
news:u9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a
ComboBox.
All the InternalControl s are Private and some are allowed to be
accessed through Public Methods.
One of the things I would like to do (of course) is set the
DataBindings.
Something clearly is wrong with the approach I use, because I can't
set the Properties in the Designer, the DataSource-Property appears like
'ReadOnly', there is no "dropdown" with the list from
System.Windows. Forms.ListContr ol

Dim _DataSource As Object
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Th e data source for the dropdown list."),
Category("Data" )> _
Public Overridable Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Sp ecifies the property of the data source whose content
you want to display."), Category("Data" )> _
Public Overridable Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
Me.Internal_UiC omboBox.Display Member = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a
DataSet, only a DataSet.DataTab le.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #5
By the way: I guess "ExtendedDataGr id.Utilities.Da taMemberFieldEd itor" is a
Custom EditorType?

"Ernest Morariu" <er****@gesora. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I'm still trying to figure out how to list the DisplayMembers & ValueMembers
in the Dropdown of the Property-Designer.


<Category("So me Category"),Defa ultValueAttribu te(""),
RefreshProperti es(RefreshPrope rties.Repaint),
Editor(typeof(E xtendedDataGrid .Utilities.Data MemberFieldEdit or),
typeof(System.D rawing.Design.U ITypeEditor))> _
Public Property DisplayMember() as String
'...
End Property

Ernest

"Michael Maes" <mi*****@merlot .com> wrote in message
news:O#******** ******@tk2msftn gp13.phx.gbl...
Hi Jared,

Of course you're right. Maybe I didn't express myself too clear. (which
often happens, so I've added a pic to clarify)
If I declare the Property as an IEnumerable, then I get an imlpicit
TypeConversion Error since a DataSet doesn't implement the IEnumerable
interface.

Bit by bit the puzzle is "coming to pieces" and I've got the DataSource
(Object) & the DataMember-Properties working just fine now (I used a
TypeConverter and a UITypeEditor). I'm still trying to figure out how to
list the DisplayMembers & ValueMembers in the Dropdown of the
Property-Designer.

So basically my issue is one of the IDE. I can set my properties through
code without any problem, but I want a developer to be able to select the
available DataSources, DataMembers and DataColums in a Dropdown......

Regards,

Michael
"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
Michael,
Forgive my ignorance, but, doesn't the designer only support strong
types? Now I am curious to see the answer.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi Jared,

Thanks for your reply.
This won't do the trick because I want my control to be able to bind

to ILists and ICollections. As I want to be able to set the Datasource & the
Datamember apart, I can't bind to a DataSource in this case.

I want my bindings set like: (both in the Property-Designer as in
Run--Time)

With UC
.DataSource = DataSource (eg DataSet) --> This wont work.
.DataMember = "DataTable"
.DisplayMember = "Column"
.ValueMember = "Column"
End With

Regards,

Michael

"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
I'm just guessing here, so take this for what it's worth; instead of
using an object could you try to bind to some IEnumerable or other interface object? That way you know the datasource is supported and the designer know what type(s) of objects to expect. I don't know if IEnumerable is the right interface for you but it will work in this example.

Dim DataSource as IEnumerable

Public Overridable Property DataSource() As IEnumerable
Get
Return _DataSource
End Get
Set(ByVal Value As IEnumerable)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\ Path_to_some_xm l_file\MyFile.x ml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol .DataSource = ds.Tables(0).De faultView
Me.MyUserContro l.DisplayMember = "SomeProper ty"

-- or --

The designer will display all IEnumerable interfaces and allow you to choose a datasource that will work with your object.

I looked up the combo box in the Object browser, it looks like it
supports IList, IEnumerable and ICollection. Both IList and ICollection
implement IEnumerable.

Hope this helps.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message
news:u9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a
ComboBox.
All the InternalControl s are Private and some are allowed to be
accessed through Public Methods.
One of the things I would like to do (of course) is set the
DataBindings.
Something clearly is wrong with the approach I use, because I can't set the Properties in the Designer, the DataSource-Property appears like
'ReadOnly', there is no "dropdown" with the list from
System.Windows. Forms.ListContr ol

Dim _DataSource As Object
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Th e data source for the dropdown list."),
Category("Data" )> _
Public Overridable Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Sp ecifies the property of the data source whose content you want to display."), Category("Data" )> _
Public Overridable Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
Me.Internal_UiC omboBox.Display Member = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a
DataSet, only a DataSet.DataTab le.DataColumn.

What is wrong with my approach?

TIA,

Michael

Nov 20 '05 #6
Michael,
I don't know if this will help, it contains some examples on adding
custom lists to the PropertyGrid control. If it doesn't solve your problem
it may help to push you in the right direction.
Jared

http://codeproject.com/vb/net/using_propertygrid.asp
"Michael Maes" <mi*****@merlot .com> wrote in message
news:uw******** ********@TK2MSF TNGP10.phx.gbl. ..
By the way: I guess "ExtendedDataGr id.Utilities.Da taMemberFieldEd itor" is
a
Custom EditorType?

"Ernest Morariu" <er****@gesora. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
>I'm still trying to figure out how to list the DisplayMembers &

ValueMembers
>in the Dropdown of the Property-Designer.


<Category("So me Category"),Defa ultValueAttribu te(""),
RefreshProperti es(RefreshPrope rties.Repaint),
Editor(typeof(E xtendedDataGrid .Utilities.Data MemberFieldEdit or),
typeof(System.D rawing.Design.U ITypeEditor))> _
Public Property DisplayMember() as String
'...
End Property

Ernest

"Michael Maes" <mi*****@merlot .com> wrote in message
news:O#******** ******@tk2msftn gp13.phx.gbl...
Hi Jared,

Of course you're right. Maybe I didn't express myself too clear. (which
often happens, so I've added a pic to clarify)
If I declare the Property as an IEnumerable, then I get an imlpicit
TypeConversion Error since a DataSet doesn't implement the IEnumerable
interface.

Bit by bit the puzzle is "coming to pieces" and I've got the DataSource
(Object) & the DataMember-Properties working just fine now (I used a
TypeConverter and a UITypeEditor). I'm still trying to figure out how to
list the DisplayMembers & ValueMembers in the Dropdown of the
Property-Designer.

So basically my issue is one of the IDE. I can set my properties through
code without any problem, but I want a developer to be able to select the
available DataSources, DataMembers and DataColums in a Dropdown......

Regards,

Michael
"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
Michael,
Forgive my ignorance, but, doesn't the designer only support strong
types? Now I am curious to see the answer.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi Jared,

Thanks for your reply.
This won't do the trick because I want my control to be able to bind

to
ILists and ICollections. As I want to be able to set the Datasource & the
Datamember apart, I can't bind to a DataSource in this case.

I want my bindings set like: (both in the Property-Designer as in
Run--Time)

With UC
.DataSource = DataSource (eg DataSet) --> This wont work.
.DataMember = "DataTable"
.DisplayMember = "Column"
.ValueMember = "Column"
End With

Regards,

Michael

"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
I'm just guessing here, so take this for what it's worth; instead
of
using an object could you try to bind to some IEnumerable or other

interface
object? That way you know the datasource is supported and the designer

know
what type(s) of objects to expect. I don't know if IEnumerable is the

right
interface for you but it will work in this example.

Dim DataSource as IEnumerable

Public Overridable Property DataSource() As IEnumerable
Get
Return _DataSource
End Get
Set(ByVal Value As IEnumerable)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\ Path_to_some_xm l_file\MyFile.x ml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol .DataSource = ds.Tables(0).De faultView
Me.MyUserContro l.DisplayMember = "SomeProper ty"

-- or --

The designer will display all IEnumerable interfaces and allow you

to
choose a datasource that will work with your object.

I looked up the combo box in the Object browser, it looks like it
supports IList, IEnumerable and ICollection. Both IList and ICollection
implement IEnumerable.

Hope this helps.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message
news:u9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a
ComboBox.
All the InternalControl s are Private and some are allowed to be
accessed through Public Methods.
One of the things I would like to do (of course) is set the
DataBindings.
Something clearly is wrong with the approach I use, because I

can't
set the Properties in the Designer, the DataSource-Property appears like
'ReadOnly', there is no "dropdown" with the list from
System.Windows. Forms.ListContr ol

Dim _DataSource As Object
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Th e data source for the dropdown list."),
Category("Data" )> _
Public Overridable Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Sp ecifies the property of the data source whose

content
you want to display."), Category("Data" )> _
Public Overridable Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
Me.Internal_UiC omboBox.Display Member = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a
DataSet, only a DataSet.DataTab le.DataColumn.

What is wrong with my approach?

TIA,

Michael


Nov 20 '05 #7
> By the way: I guess "ExtendedDataGr id.Utilities.Da taMemberFieldEd itor" is
a
Custom EditorType?
Yes, it is a cutom editor. Sorry, I haven't noticed this.
In your case , you don't need to use a custom DataMemberField Editor. You
can use the one of the framework, as you already did.
I think you forgot this attribute:
RefreshProperti es(RefreshPrope rties.All)
If is set the DataBindings like:
DataSource = DataSet
DataMember = DataTable

I think this is not a valid code. Usualy, the DataMember property is of type
string, so you cannot set a DataTable object to a property of type String.

You make a little confusion. You are talking about DisplayMember,
ValueMember (that are to be found in ListBox, Combobox controls) and then
you are talking about DataMember that is to be found only in a DataGrid.

Usually the DataMember property is used to specify the table name inside the
DataSet.
DataSource=myDa taSetObject
DataMember= "myTable"

Ernest

Yes it is
"Michael Maes" <mi*****@merlot .com> wrote in message
news:uw******** ******@TK2MSFTN GP10.phx.gbl... By the way: I guess "ExtendedDataGr id.Utilities.Da taMemberFieldEd itor" is a Custom EditorType?

"Ernest Morariu" <er****@gesora. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I'm still trying to figure out how to list the DisplayMembers &

ValueMembers
in the Dropdown of the Property-Designer.


<Category("So me Category"),Defa ultValueAttribu te(""),
RefreshProperti es(RefreshPrope rties.Repaint),
Editor(typeof(E xtendedDataGrid .Utilities.Data MemberFieldEdit or),
typeof(System.D rawing.Design.U ITypeEditor))> _
Public Property DisplayMember() as String
'...
End Property

Ernest

"Michael Maes" <mi*****@merlot .com> wrote in message
news:O#******** ******@tk2msftn gp13.phx.gbl...
Hi Jared,

Of course you're right. Maybe I didn't express myself too clear. (which
often happens, so I've added a pic to clarify)
If I declare the Property as an IEnumerable, then I get an imlpicit
TypeConversion Error since a DataSet doesn't implement the IEnumerable
interface.

Bit by bit the puzzle is "coming to pieces" and I've got the DataSource
(Object) & the DataMember-Properties working just fine now (I used a
TypeConverter and a UITypeEditor). I'm still trying to figure out how to
list the DisplayMembers & ValueMembers in the Dropdown of the
Property-Designer.

So basically my issue is one of the IDE. I can set my properties through
code without any problem, but I want a developer to be able to select the available DataSources, DataMembers and DataColums in a Dropdown......

Regards,

Michael
"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
Michael,
Forgive my ignorance, but, doesn't the designer only support strong types? Now I am curious to see the answer.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi Jared,

Thanks for your reply.
This won't do the trick because I want my control to be able to bind

to
ILists and ICollections. As I want to be able to set the Datasource & the Datamember apart, I can't bind to a DataSource in this case.

I want my bindings set like: (both in the Property-Designer as in
Run--Time)

With UC
.DataSource = DataSource (eg DataSet) --> This wont work.
.DataMember = "DataTable"
.DisplayMember = "Column"
.ValueMember = "Column"
End With

Regards,

Michael

"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
I'm just guessing here, so take this for what it's worth; instead of using an object could you try to bind to some IEnumerable or other

interface
object? That way you know the datasource is supported and the designer

know
what type(s) of objects to expect. I don't know if IEnumerable is the

right
interface for you but it will work in this example.

Dim DataSource as IEnumerable

Public Overridable Property DataSource() As IEnumerable
Get
Return _DataSource
End Get
Set(ByVal Value As IEnumerable)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\ Path_to_some_xm l_file\MyFile.x ml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol .DataSource = ds.Tables(0).De faultView
Me.MyUserContro l.DisplayMember = "SomeProper ty"

-- or --

The designer will display all IEnumerable interfaces and allow you

to
choose a datasource that will work with your object.

I looked up the combo box in the Object browser, it looks like it
supports IList, IEnumerable and ICollection. Both IList and ICollection
implement IEnumerable.

Hope this helps.
Jared
"Michael Maes" <mi*****@merlot .com> wrote in message
news:u9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a
ComboBox.
All the InternalControl s are Private and some are allowed to be
accessed through Public Methods.
One of the things I would like to do (of course) is set the
DataBindings.
Something clearly is wrong with the approach I use, because I

can't
set the Properties in the Designer, the DataSource-Property appears like
'ReadOnly', there is no "dropdown" with the list from
System.Windows. Forms.ListContr ol

Dim _DataSource As Object
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Th e data source for the dropdown list."),
Category("Data" )> _
Public Overridable Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
Me.Internal_UiC omboBox.DataSou rce = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Browsable(True) , _
Description("Sp ecifies the property of the data source whose

content
you want to display."), Category("Data" )> _
Public Overridable Property DisplayMember() As String
Get
Return _DisplayMember
End Get
Set(ByVal Value As String)
_DisplayMember = Value
Me.Internal_UiC omboBox.Display Member = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a
DataSet, only a DataSet.DataTab le.DataColumn.

What is wrong with my approach?

TIA,

Michael


Nov 20 '05 #8
I think you forgot this attribute:
RefreshProperti es(RefreshPrope rties.All)
I already tried that. Didn't work :-(
You make a little confusion. You are talking about DisplayMember,
ValueMember (that are to be found in ListBox, Combobox controls) and then
you are talking about DataMember that is to be found only in a DataGrid.
I'm sorry. I wasn't talking about System.Windows. Forms.ComboBox but a
"Custom ComboBox" (more like a 'Dropdown DataGrid'). The issue is passing
Databinding to a UserControl, so I forgot about the Custom ComboBox.
Usually the DataMember property is used to specify the table name inside the DataSet.
DataSource=myDa taSetObject
DataMember= "myTable"


That is exactly what I need.

I'm going to look at the Sample Jared pointed out.

Regards,

Michael
Nov 20 '05 #9
Hi Michael,

Based on my test with your code, if we set the dataset.datatab le in the
datasource, in the displaymember and the valuemember we can only choose the
column from the table we specified according to my understanding of the
picture that you post and named it as wanted. Is that what you want?

So my understanding is that you want when you set the datasouce to dataset,
and datamember to datatable, then the displaymember and value member should
be in the datatable specifed before.

It seems that you wants the similar behavor with ListBox in .net frame.
If we set the display member and value member in different table a
exception will be thrown.
So I think we can do the similar thing in the usercontrol, and can write a
if--else statement in the Set of DisplayMember and ValueMember to judge the
binding context, if they are not in the table of datamember, then we can
throw the argument exception as the listbox do, so that we can avoid the
user make displaymember and valuemember bind to two different tables.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1672
by: Jason Wright via .NET 247 | last post by:
Hiya, I've created a UserControl with some Custom properties and assigned databinding expressions to the properties in the aspx. Does anyone know why these expressions are not being evaluated? eg. <uc1:ControlX id="la" runat="server" ClientClick='javascriptfunction(<%# DataBinder.Eval(Container.DataItem, "Id")%>)' /> after processing renders in html as <table id="la" onclick="javascriptfunction(<%#...
0
1411
by: vbMental | last post by:
I'm almost certain this is a bug, or atleast "undesirable behavior". I felt the checkbox list control had shortcomings so I ventured on creating my own checkbox list user control. To put it shortly, the usercontrol had a checkbox list inside of it, that would be bound by a datasource that was to be specified as a property of the control. It also had an all checkbox at the top that would select all of the checkboxes in the list... The...
0
1119
by: vbMental | last post by:
I created a user control that, had a datalist with checkboxes inside of the item template. These checkboxes would not retain state. For instance, if I set them to checked inside of the load event of the UserControl, they would appear false(the default value) when inside the top level datagrid. Here's the walkthrough (tried to make it as quick as possible): Start a new ASP.NET Web Application project. 1. Create a usercontrol....
6
1945
by: Pete Davis | last post by:
I'm fairly weak with ASP.NET. What I'm trying to do is pass an attribute to a UserControl. The attribute is a value from the CodeBehind for the page. So in my .aspx I have the following: <cm:Comments runat="server" ID="Comments1" CommentType="News" ItemID="<%= NewsItemID %>" /> NewsItemID is a property in the CodeBehind for the page.
1
3257
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an SQLDataSource. The GridView contains 3 columns: QuestionNumber, QuestionText, and a TemplateField. Each row in the GridView represents a question in a table (Ex.: "18. Satisfaction Level").
2
3400
by: gerry | last post by:
based on MSPress's ASP.NET 2.0 Applications Advaced Topics ( Table 12-3 p.472 ), and most events should be automatically wired up when @Control AutoEventWireup="true". ie. Page_InitComplete() {} should be invoked automatically without having to wire up the event as : Page.InitComplete+=new EventHandler(Page_InitComplete); It seems that this is only true for a fairly restricted set of events which does not include Page_InitComplete. I...
6
12152
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use binding like normal. The problem I am running into is that my UserControl ends up with a different BindingContext then the ParentForm it is contained in and thus all other controls on the parent form. (I want various controls on the form to...
1
2434
by: Stephen Barrett | last post by:
I have an application that was originally built with ASP.Net 1.1. We finally got permission to migrate to 2.0. Due to time constraints we migrated the web projects to 2.0 web application projects to minimize required changes initially. I am stuck on a problem using a data grid. I have a usercontrol that has a DataGrid on it. The datagrid has an item template that loads another common user control for every row. I am getting
1
1599
by: mAbZ | last post by:
I neeed to instantiate an UserControl in an aspx page like this: <MyNamespace:MyControl ID="ctrl1" runat="server" MyParent="<%# this %>" /> where "this" is the current aspx page and should be assigned to property Parent contained in MyControl class. Above code is contained in a PlaceHolder. When debuging, "this" is not null (obviously) but value in MyParent property's setter is null.
0
9920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10699
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10790
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9535
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5960
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4580
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4176
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.