By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 991 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

UserControl: Databinding

P: n/a
Hi,

I have a UserControl containing some controls of which one is a ComboBox.
All the InternalControls 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.ListControl

Dim _DataSource As Object
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("The 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_UiComboBox.DataSource = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("Specifies 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_UiComboBox.DisplayMember = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a DataSet, only a DataSet.DataTable.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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_UiComboBox.DataSource = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\Path_to_some_xml_file\MyFile.xml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol.DataSource = ds.Tables(0).DefaultView
Me.MyUserControl.DisplayMember = "SomeProperty"

-- 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**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a ComboBox.
All the InternalControls 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.ListControl

Dim _DataSource As Object
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("The 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_UiComboBox.DataSource = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("Specifies 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_UiComboBox.DisplayMember = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a DataSet, only a DataSet.DataTable.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #2

P: n/a
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.supernews.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_UiComboBox.DataSource = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\Path_to_some_xml_file\MyFile.xml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol.DataSource = ds.Tables(0).DefaultView
Me.MyUserControl.DisplayMember = "SomeProperty"

-- 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**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a ComboBox.
All the InternalControls 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.ListControl

Dim _DataSource As Object
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("The 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_UiComboBox.DataSource = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("Specifies 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_UiComboBox.DisplayMember = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a DataSet, only a DataSet.DataTable.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #3

P: n/a
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****************@tk2msftngp13.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.supernews.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_UiComboBox.DataSource = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\Path_to_some_xml_file\MyFile.xml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol.DataSource = ds.Tables(0).DefaultView
Me.MyUserControl.DisplayMember = "SomeProperty"

-- 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**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a ComboBox.
All the InternalControls 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.ListControl

Dim _DataSource As Object
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("The 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_UiComboBox.DataSource = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("Specifies 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_UiComboBox.DisplayMember = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a DataSet, only a DataSet.DataTable.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #4

P: n/a
>I'm still trying to figure out how to list the DisplayMembers &
ValueMembers
in the Dropdown of the Property-Designer.


<Category("Some Category"),DefaultValueAttribute(""),
RefreshProperties(RefreshProperties.Repaint),
Editor(typeof(ExtendedDataGrid.Utilities.DataMembe rFieldEditor),
typeof(System.Drawing.Design.UITypeEditor))> _
Public Property DisplayMember() as String
'...
End Property

Ernest

"Michael Maes" <mi*****@merlot.com> wrote in message
news:O#**************@tk2msftngp13.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.supernews.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****************@tk2msftngp13.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.supernews.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_UiComboBox.DataSource = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\Path_to_some_xml_file\MyFile.xml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol.DataSource = ds.Tables(0).DefaultView
Me.MyUserControl.DisplayMember = "SomeProperty"

-- 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**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a
ComboBox.
All the InternalControls 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.ListControl

Dim _DataSource As Object
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("The 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_UiComboBox.DataSource = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("Specifies 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_UiComboBox.DisplayMember = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a
DataSet, only a DataSet.DataTable.DataColumn.

What is wrong with my approach?

TIA,

Michael
Nov 20 '05 #5

P: n/a
By the way: I guess "ExtendedDataGrid.Utilities.DataMemberFieldEdi tor" is a
Custom EditorType?

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


<Category("Some Category"),DefaultValueAttribute(""),
RefreshProperties(RefreshProperties.Repaint),
Editor(typeof(ExtendedDataGrid.Utilities.DataMembe rFieldEditor),
typeof(System.Drawing.Design.UITypeEditor))> _
Public Property DisplayMember() as String
'...
End Property

Ernest

"Michael Maes" <mi*****@merlot.com> wrote in message
news:O#**************@tk2msftngp13.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.supernews.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****************@tk2msftngp13.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.supernews.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_UiComboBox.DataSource = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\Path_to_some_xml_file\MyFile.xml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol.DataSource = ds.Tables(0).DefaultView
Me.MyUserControl.DisplayMember = "SomeProperty"

-- 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**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a
ComboBox.
All the InternalControls 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.ListControl

Dim _DataSource As Object
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("The 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_UiComboBox.DataSource = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("Specifies 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_UiComboBox.DisplayMember = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a
DataSet, only a DataSet.DataTable.DataColumn.

What is wrong with my approach?

TIA,

Michael

Nov 20 '05 #6

P: n/a
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****************@TK2MSFTNGP10.phx.gbl...
By the way: I guess "ExtendedDataGrid.Utilities.DataMemberFieldEdi tor" is
a
Custom EditorType?

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

ValueMembers
>in the Dropdown of the Property-Designer.


<Category("Some Category"),DefaultValueAttribute(""),
RefreshProperties(RefreshProperties.Repaint),
Editor(typeof(ExtendedDataGrid.Utilities.DataMembe rFieldEditor),
typeof(System.Drawing.Design.UITypeEditor))> _
Public Property DisplayMember() as String
'...
End Property

Ernest

"Michael Maes" <mi*****@merlot.com> wrote in message
news:O#**************@tk2msftngp13.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.supernews.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****************@tk2msftngp13.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.supernews.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_UiComboBox.DataSource = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\Path_to_some_xml_file\MyFile.xml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol.DataSource = ds.Tables(0).DefaultView
Me.MyUserControl.DisplayMember = "SomeProperty"

-- 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**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a
ComboBox.
All the InternalControls 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.ListControl

Dim _DataSource As Object
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("The 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_UiComboBox.DataSource = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("Specifies 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_UiComboBox.DisplayMember = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a
DataSet, only a DataSet.DataTable.DataColumn.

What is wrong with my approach?

TIA,

Michael


Nov 20 '05 #7

P: n/a
> By the way: I guess "ExtendedDataGrid.Utilities.DataMemberFieldEdi tor" 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 DataMemberFieldEditor. You
can use the one of the framework, as you already did.
I think you forgot this attribute:
RefreshProperties(RefreshProperties.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=myDataSetObject
DataMember= "myTable"

Ernest

Yes it is
"Michael Maes" <mi*****@merlot.com> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl... By the way: I guess "ExtendedDataGrid.Utilities.DataMemberFieldEdi tor" is a Custom EditorType?

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

ValueMembers
in the Dropdown of the Property-Designer.


<Category("Some Category"),DefaultValueAttribute(""),
RefreshProperties(RefreshProperties.Repaint),
Editor(typeof(ExtendedDataGrid.Utilities.DataMembe rFieldEditor),
typeof(System.Drawing.Design.UITypeEditor))> _
Public Property DisplayMember() as String
'...
End Property

Ernest

"Michael Maes" <mi*****@merlot.com> wrote in message
news:O#**************@tk2msftngp13.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.supernews.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****************@tk2msftngp13.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.supernews.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_UiComboBox.DataSource = Value
End Set
End Property

in your project you could do something like

Dim ds As New DataSet
ds.ReadXml("C:\Path_to_some_xml_file\MyFile.xml")
'DataSet doesn't support IEnumerable, DataView does
Me.MyUserConrol.DataSource = ds.Tables(0).DefaultView
Me.MyUserControl.DisplayMember = "SomeProperty"

-- 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**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a UserControl containing some controls of which one is a
ComboBox.
All the InternalControls 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.ListControl

Dim _DataSource As Object
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("The 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_UiComboBox.DataSource = Value
End Set
End Property

Dim _DisplayMember As String
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Description("Specifies 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_UiComboBox.DisplayMember = Value
End Set
End Property
In the Advanced Wizard I can Set a Value, only, I can't set a
DataSet, only a DataSet.DataTable.DataColumn.

What is wrong with my approach?

TIA,

Michael


Nov 20 '05 #8

P: n/a
I think you forgot this attribute:
RefreshProperties(RefreshProperties.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=myDataSetObject
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

P: n/a
Hi Michael,

Based on my test with your code, if we set the dataset.datatable 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

P: n/a
Hi Peter,

Thanks for your reply.
I'm sorry for my late reply, but we have experienced a major system-crash so
I've been "out-of-order" for a while.

Your understandings of my requirements are completely right.
Adding a conditional check to the Get is not a problem at all, only I would
prefer that only the columns of the Table selected in de DataMember are
shown.
I think I will have to write my own custom Editor for that, so I guess I'll
be looking in that direction now.

Regards,

Michael
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:rL*************@cpmsftngxa10.phx.gbl...
Hi Michael,

Based on my test with your code, if we set the dataset.datatable 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 #11

P: n/a
> 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.
I made many controls this way and they works properly.

Tell me what is the name of your property representing the data source at
the UserControl level.

Ernest
"Michael Maes" <mi*****@merlot.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
I think you forgot this attribute:
RefreshProperties(RefreshProperties.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=myDataSetObject
DataMember= "myTable"


That is exactly what I need.

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

Regards,

Michael

Nov 20 '05 #12

P: n/a
I meant 'Set' of course....
Nov 20 '05 #13

P: n/a
Hi Michael,

So far I think we would better do the job as the listbox do in the .net
framework. And I think It is hard to implement a customized Editor.

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

This discussion thread is closed

Replies have been disabled for this discussion.