Hello,
I am trying to bind a datatable to a radmenucomboitem in a context menu, that is used by a treeview control. I set the datasource, valuemember and displaymember on form load, and then attach the context menu to each tree node after the treeview has been loaded. When I run the app, the combobox displays, but it is empty. What could I be missing? Thanks!
I am trying to bind a datatable to a radmenucomboitem in a context menu, that is used by a treeview control. I set the datasource, valuemember and displaymember on form load, and then attach the context menu to each tree node after the treeview has been loaded. When I run the app, the combobox displays, but it is empty. What could I be missing? Thanks!
radMenuComboItem1.ComboBoxElement.ValueMember =
"ENTITY_ID"
radMenuComboItem1.ComboBoxElement.DisplayMember =
"NAME"
radMenuComboItem1.ComboBoxElement.DataSource = _dsTemp.MDMGroup
11 Answers, 1 is accepted
0
Richard Slade
Top achievements
Rank 2
answered on 18 Nov 2010, 02:49 PM
Hi Sonya L,
Could you post more of your code? For exmaple, how are you attaching the contextmenu to each node? If you can post an example that replicates this I will take a look at it for you.
From what I understand so far, your treeview displays the data, you right click for the context menu and the context menu displays, but the combobox inside the context menu does not have any data.
Thanks
Richard
Could you post more of your code? For exmaple, how are you attaching the contextmenu to each node? If you can post an example that replicates this I will take a look at it for you.
From what I understand so far, your treeview displays the data, you right click for the context menu and the context menu displays, but the combobox inside the context menu does not have any data.
Thanks
Richard
0
Sonya L
Top achievements
Rank 1
answered on 18 Nov 2010, 03:18 PM
Yes, your assumptions are correct. This is the function that set the menu:
I use a binding list to bind to my tree (the list is loaded from datatables), and then I call the above. So, I set the menu combobox datasource (after loading the datatable), load the tree, then call the above to attach the menu.
Public
Sub
SetMenu(
ByRef
nodesCollection
As
RadTreeNodeCollection)
For
Each
nd
As
RadTreeNode
In
nodesCollection
If
nd.Nodes.Count = 0
Then
nd.ContextMenu = rcmRightClick
ElseIf
nd.Nodes.Count > 0
Then
nd.ContextMenu = rcmRightClick
For
Each
cn
As
RadTreeNode
In
nd.Nodes
SetMenu(nd.Nodes)
Next
End
If
Next
End
Sub
I use a binding list to bind to my tree (the list is loaded from datatables), and then I call the above. So, I set the menu combobox datasource (after loading the datatable), load the tree, then call the above to attach the menu.
0
Richard Slade
Top achievements
Rank 2
answered on 18 Nov 2010, 05:06 PM
Hi,
I could also not get this to bind via a datasource so it could be seen and had to resort to adding the items manually.
Hope this helps
Richard
I could also not get this to bind via a datasource so it could be seen and had to resort to adding the items manually.
Imports
Telerik.WinControls
Imports
Telerik.WinControls.UI
Public
Class
Form1
Private
m_ContextMenu
As
RadContextMenu
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
, _
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
Me
.RadTreeView1.Nodes.Add(
"Node 1"
)
Me
.RadTreeView1.Nodes.Add(
"Node 2"
)
Me
.RadTreeView1.Nodes.Add(
"Node 3"
)
Me
.RadTreeView1.Nodes.Add(
"Node 4"
)
m_ContextMenu =
New
RadContextMenu()
Dim
comboItem
As
New
RadMenuComboItem()
Dim
people
As
New
List(Of Person)
people.Add(
New
Person(1,
"Richard"
))
people.Add(
New
Person(2,
"Sonya"
))
For
Each
p
As
Person
In
people
Dim
item
As
New
RadComboBoxItem()
item.Text = p.Name
item.Value = p.Id
comboItem.Items.Add(item)
Next
Dim
comboElement
As
RadComboBoxElement = comboItem.ComboBoxElement
AddHandler
comboElement.SelectedValueChanged,
AddressOf
ComboSelectedValueChanged
m_ContextMenu.Items.Add(comboItem)
SetMenu(
Me
.RadTreeView1.Nodes)
End
Sub
Private
Sub
ComboSelectedValueChanged(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
MessageBox.Show(
DirectCast
(sender, RadComboBoxElement).SelectedValue.ToString())
End
Sub
Public
Sub
SetMenu(
ByRef
nodesCollection
As
RadTreeNodeCollection)
For
Each
nd
As
RadTreeNode
In
nodesCollection
If
nd.Nodes.Count = 0
Then
nd.ContextMenu = m_ContextMenu
ElseIf
nd.Nodes.Count > 0
Then
nd.ContextMenu = m_ContextMenu
For
Each
cn
As
RadTreeNode
In
nd.Nodes
SetMenu(nd.Nodes)
Next
End
If
Next
End
Sub
End
Class
Public
Class
Person
Private
m_Id
As
Integer
Private
m_Name
As
String
Public
Sub
New
(
ByVal
id
As
Integer
,
ByVal
name
As
String
)
m_Name = name
m_Id = id
End
Sub
Public
ReadOnly
Property
Name()
As
String
Get
Return
m_Name
End
Get
End
Property
Public
ReadOnly
Property
Id()
As
Integer
Get
Return
m_Id
End
Get
End
Property
End
Class
Hope this helps
Richard
0
Sonya L
Top achievements
Rank 1
answered on 18 Nov 2010, 05:22 PM
Yes, you're right. Adding the items manually does work, and I can probably use this as a workaround if needed. Maybe someone from Telerik can comment on why the binding doesn't work. Thanks for your help!
0
Richard Slade
Top achievements
Rank 2
answered on 18 Nov 2010, 05:24 PM
you're welcome Sonya. My apologies I couldn't get that working for you.
Richard
Richard
0
Hi Sonya,
Since adding items manually works fine on your end, I suppose that the issue is related with the data binding. Please refer to the following help article which you might find helpful - Databinding Basics.
In case you still experience the issue, I would like to kindly ask you to open a new support ticket where you can attach your project and your DB (or a sample project with a sample DB) that demonstrates this issue. This will allow us to investigate your case and provide you with further assistance.
Looking forward to your reply.
Kind regards,
Stefan
the Telerik team
Since adding items manually works fine on your end, I suppose that the issue is related with the data binding. Please refer to the following help article which you might find helpful - Databinding Basics.
In case you still experience the issue, I would like to kindly ask you to open a new support ticket where you can attach your project and your DB (or a sample project with a sample DB) that demonstrates this issue. This will allow us to investigate your case and provide you with further assistance.
Looking forward to your reply.
Kind regards,
Stefan
the Telerik team
0
Richard Slade
Top achievements
Rank 2
answered on 23 Nov 2010, 01:27 PM
Hi Stefan,
Just to back up what Sonya was saying, if you declare the following:
(person class)
then the count is always 0. I don't think I'm going mad, but it's always possible!
Hope this helps
Kind regards,
Richard
Just to back up what Sonya was saying, if you declare the following:
Dim
comboItem
As
New
RadMenuComboItem()
Dim
people
As
New
List(Of Person)
people.Add(
New
Person(1,
"Richard"
))
people.Add(
New
Person(2,
"Sonya"
))
comboItem.ComboBoxElement.DataSource = people
comboItem.ComboBoxElement.ValueMember =
"Id"
comboItem.ComboBoxElement.DisplayMember =
"Name"
MessageBox.Show(
"Combo Items Count: "
& comboItem.Items.Count.ToString())
MessageBox.Show(
"Combo Element Items Count: "
& comboItem.ComboBoxElement.Items.Count.ToString())
(person class)
Public
Class
Person
Private
m_Id
As
Integer
Private
m_Name
As
String
Public
Sub
New
(
ByVal
id
As
Integer
,
ByVal
name
As
String
)
m_Name = name
m_Id = id
End
Sub
Public
Property
Name()
As
String
Get
Return
m_Name
End
Get
Set
(
ByVal
value
As
String
)
m_Name = value
End
Set
End
Property
Public
Property
Id()
As
Integer
Get
Return
m_Id
End
Get
Set
(
ByVal
value
As
Integer
)
m_Id = value
End
Set
End
Property
End
Class
then the count is always 0. I don't think I'm going mad, but it's always possible!
Hope this helps
Kind regards,
Richard
0
Sonya L
Top achievements
Rank 1
answered on 23 Nov 2010, 03:09 PM
For now, I'm going to go with the workaround, but if it gets too slow, I'll look into it further. However, since Richard can reproduce this, I'm sure we aren't the only ones with the issue. Thanks, Richard, for the additional example.
0
Hi guys,
Thanks to the last post of Richard I was able to understand where the problem comes from. In this scenario when you are working with RadMenuComboItem, you have to specify the BindingContext of the menu item explicitly. Please add this line of code right before the data source setting:
I hope this information addresses your question. Let me know if you need further assistance.
Regards,
Stefan
the Telerik team
Thanks to the last post of Richard I was able to understand where the problem comes from. In this scenario when you are working with RadMenuComboItem, you have to specify the BindingContext of the menu item explicitly. Please add this line of code right before the data source setting:
comboItem.BindingContext =
Me
.BindingContext
I hope this information addresses your question. Let me know if you need further assistance.
Regards,
Stefan
the Telerik team
0
Richard Slade
Top achievements
Rank 2
answered on 26 Nov 2010, 10:41 AM
Hi Stefan,
Thanks for the information. Is this something that you have plans to change? I don't think it's obvious to have to do this.
Many thanks
Richard
Thanks for the information. Is this something that you have plans to change? I don't think it's obvious to have to do this.
Many thanks
Richard
0
Hi Sonya,
Since Q2 2010 we have introduced a new control called RadDropDownList which has more intuitive binding (you do not need to set the BindingContext). Our plans are to gradually replace the ComboBox control with RadDropDownList control.
I hope this information answers your question. Do not hesitate to contact me if you need any other information.
Regards,
Stefan
the Telerik team
Since Q2 2010 we have introduced a new control called RadDropDownList which has more intuitive binding (you do not need to set the BindingContext). Our plans are to gradually replace the ComboBox control with RadDropDownList control.
I hope this information answers your question. Do not hesitate to contact me if you need any other information.
Regards,
Stefan
the Telerik team