I'm using the following straight from the help file to load a textboxelement to a RadMenu of:
(VS2008 VB.NET)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim textItem As New RadMenuContentItem()
Dim textBox As New RadTextBoxElement()
textBox.Text = "Enter text here"
textBox.MinSize = New Size(100, 0)
textItem.ContentElement = textBox
textItem.ContentElement.AutoSizeMode = RadAutoSizeMode.WrapAroundChildren
radMenu1.Items.Add(textItem)
Dim buttonItem As New RadMenuContentItem()
Dim button As New RadButtonElement()
button.Text = "OK"
AddHandler button.Click, AddressOf button_Click
buttonItem.ContentElement = button
radMenu1.Items.Add(buttonItem)
End Sub
Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim contentItem As RadMenuContentItem = TryCast(radMenu1.Items(0), RadMenuContentItem)
Dim textBox As RadTextBoxElement = TryCast(contentItem.ContentElement, RadTextBoxElement)
MessageBox.Show("Text is: " + textBox.Text)
End Sub
However I get the following error:
at radMenu1.Items.Add(textItem)
What do I need to do differently?
Thanks
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Telerik.WinControls.UI"
StackTrace:
at Telerik.WinControls.UI.RadMenuContentItem.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.Layout.WrapLayoutPanel.arrangeLine(Single v, Single lineV, Int32 start, Int32 end, Boolean useItemU, Single itemU)
at Telerik.WinControls.Layout.WrapLayoutPanel.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.RadElement.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.RootRadElement.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RootRadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayout()
at Telerik.WinControls.RadElement.UpdateLayout()
at Telerik.WinControls.ComponentLayoutElementTree.GetPreferredSize(Size sizeConstraints)
at Telerik.WinControls.RadControl.GetPreferredSize(Size proposedSize)
at System.Windows.Forms.Layout.DefaultLayout.xGetDockedSize(IArrangedElement element, Size remainingSize, Size constraints, Boolean measureOnly)
at System.Windows.Forms.Layout.DefaultLayout.GetVerticalDockedSize(IArrangedElement element, Size remainingSize, Boolean measureOnly)
at System.Windows.Forms.Layout.DefaultLayout.LayoutDockedControls(IArrangedElement container, Boolean measureOnly)
at System.Windows.Forms.Layout.DefaultLayout.xLayout(IArrangedElement container, Boolean measureOnly, Size& preferredSize)
at System.Windows.Forms.Layout.DefaultLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ContainerControl.OnLayout(LayoutEventArgs e)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Telerik.WinControls.RadControl.RegisterHostedControl(RadHostItem hostElement)
at Telerik.WinControls.RadHostItem.PerformRoutedEventAction(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadHostItem.OnTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.UI.RadTextBoxItem.OnTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.SetParent(RadElement parent)
at Telerik.WinControls.RadElement.ChangeCollection(RadElement child, ItemsChangeOperation changeOperation)
at Telerik.WinControls.RadElementCollection.OnInsertComplete(Int32 index, Object value)
at System.Collections.CollectionBase.System.Collections.IList.Insert(Int32 index, Object value)
at Telerik.WinControls.RadItemOwnerCollection.OnInsertComplete(Int32 index, Object value)
at System.Collections.CollectionBase.System.Collections.IList.Add(Object value)
at Telerik.WinControls.RadItemCollection.Add(RadItem value)
at Biosketch_2.PubMedGrid.PubMedGrid_Load(Object sender, EventArgs e) in C:\vs2008\Biosketch_2\Biosketch_2\PubMedGrid.vb:line 1729
at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
at System.Windows.Forms.UserControl.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Biosketch_2.MainForm.MainForm_Load(Object sender, EventArgs e) in C:\vs2008\Biosketch_2\Biosketch_2\MainForm.vb:line 77
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at Telerik.WinControls.RadFormBase.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Biosketch_2.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
(VS2008 VB.NET)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim textItem As New RadMenuContentItem()
Dim textBox As New RadTextBoxElement()
textBox.Text = "Enter text here"
textBox.MinSize = New Size(100, 0)
textItem.ContentElement = textBox
textItem.ContentElement.AutoSizeMode = RadAutoSizeMode.WrapAroundChildren
radMenu1.Items.Add(textItem)
Dim buttonItem As New RadMenuContentItem()
Dim button As New RadButtonElement()
button.Text = "OK"
AddHandler button.Click, AddressOf button_Click
buttonItem.ContentElement = button
radMenu1.Items.Add(buttonItem)
End Sub
Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim contentItem As RadMenuContentItem = TryCast(radMenu1.Items(0), RadMenuContentItem)
Dim textBox As RadTextBoxElement = TryCast(contentItem.ContentElement, RadTextBoxElement)
MessageBox.Show("Text is: " + textBox.Text)
End Sub
However I get the following error:
at radMenu1.Items.Add(textItem)
What do I need to do differently?
Thanks
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Telerik.WinControls.UI"
StackTrace:
at Telerik.WinControls.UI.RadMenuContentItem.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.Layout.WrapLayoutPanel.arrangeLine(Single v, Single lineV, Int32 start, Int32 end, Boolean useItemU, Single itemU)
at Telerik.WinControls.Layout.WrapLayoutPanel.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.RadElement.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.RootRadElement.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RootRadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayout()
at Telerik.WinControls.RadElement.UpdateLayout()
at Telerik.WinControls.ComponentLayoutElementTree.GetPreferredSize(Size sizeConstraints)
at Telerik.WinControls.RadControl.GetPreferredSize(Size proposedSize)
at System.Windows.Forms.Layout.DefaultLayout.xGetDockedSize(IArrangedElement element, Size remainingSize, Size constraints, Boolean measureOnly)
at System.Windows.Forms.Layout.DefaultLayout.GetVerticalDockedSize(IArrangedElement element, Size remainingSize, Boolean measureOnly)
at System.Windows.Forms.Layout.DefaultLayout.LayoutDockedControls(IArrangedElement container, Boolean measureOnly)
at System.Windows.Forms.Layout.DefaultLayout.xLayout(IArrangedElement container, Boolean measureOnly, Size& preferredSize)
at System.Windows.Forms.Layout.DefaultLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ContainerControl.OnLayout(LayoutEventArgs e)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Telerik.WinControls.RadControl.RegisterHostedControl(RadHostItem hostElement)
at Telerik.WinControls.RadHostItem.PerformRoutedEventAction(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadHostItem.OnTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.UI.RadTextBoxItem.OnTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.RaiseTunnelEvent(RadElement sender, RoutedEventArgs args)
at Telerik.WinControls.RadElement.SetParent(RadElement parent)
at Telerik.WinControls.RadElement.ChangeCollection(RadElement child, ItemsChangeOperation changeOperation)
at Telerik.WinControls.RadElementCollection.OnInsertComplete(Int32 index, Object value)
at System.Collections.CollectionBase.System.Collections.IList.Insert(Int32 index, Object value)
at Telerik.WinControls.RadItemOwnerCollection.OnInsertComplete(Int32 index, Object value)
at System.Collections.CollectionBase.System.Collections.IList.Add(Object value)
at Telerik.WinControls.RadItemCollection.Add(RadItem value)
at Biosketch_2.PubMedGrid.PubMedGrid_Load(Object sender, EventArgs e) in C:\vs2008\Biosketch_2\Biosketch_2\PubMedGrid.vb:line 1729
at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
at System.Windows.Forms.UserControl.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Biosketch_2.MainForm.MainForm_Load(Object sender, EventArgs e) in C:\vs2008\Biosketch_2\Biosketch_2\MainForm.vb:line 77
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at Telerik.WinControls.RadFormBase.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Biosketch_2.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: