This is a migrated thread and some comments may be shown as answers.

I think there is a bug in RadListBox!!!!

7 Answers 171 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mike A
Top achievements
Rank 1
Mike A asked on 29 May 2010, 04:58 AM
hello
I have 2 different Rad list boxes first one is called "LeftList" and the second one called "RightList" then i have a button when it clicked it moves the selected items from the list on the left to the list on the right  here is the code that i user to move items

    For Each item In Me.LeftList.SelectedItems
            Me.RightList.Items.Add(item)
        Next

however it is giving me errors


Here is a copy of the error

Exception has been thrown by the target of an invocation.


Action details
{"Exception has been thrown by the target of an invocation."}
System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEnt ry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuarante edCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at Telerik.WinControls.RadControl.WndProc(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.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms .UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int 32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. Run(String[] commandLine)
at RetailManagementSystem.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.InvalidOperationException
Message="Element already added"
Source="Telerik.WinControls"
StackTrace:
at Telerik.WinControls.RadElementCollection.CheckElementAlreadyAdded(RadE lement element)
at Telerik.WinControls.RadElementCollection.OnInsert(Int32 index, Object value)
at System.Collections.CollectionBase.System.Collections.IList.Add(Object value)
at Telerik.WinControls.RadElementCollection.Add(RadElement value)
at Telerik.WinControls.UI.RadVirtualizedStackViewport.ResetVisualList(Poi nt scrollValue, Boolean isScrolling)
at Telerik.WinControls.UI.RadVirtualizedStackViewport.ResetValue(Point currentValue, Size viewportSize, Size extentSize)
at Telerik.WinControls.UI.RadScrollLayoutPanel.ResetScrollPos()
at Telerik.WinControls.UI.RadScrollLayoutPanel.ArrangeOverride(SizeF finalSize)
at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
at Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayout()
InnerException:


i tried so much but i really think there is a bug in the RadListBox controls


can i get some help with this issue please

thanks







7 Answers, 1 is accepted

Sort by
0
Neo Cortex
Top achievements
Rank 1
answered on 29 May 2010, 06:33 AM
Hi Mike,

The error is casused by not removing items from LeftList first.
Try removing items from LeftList before adding them to RightList.

Also, create a temporary list of the items first ... since removing items from LeftList while iterating through the selected items will also cause problems when there is more than one item selected.

The solution looks like this:


    Private Sub SwapItems()
        Dim items As List(Of RadListBoxItem)
        items = New List(Of RadListBoxItem)      ' temporary list
        For i As Integer = 0 To LeftList.SelectedItems.Count - 1
            items.Add(LeftList.SelectedItems(i))
        Next

        For Each item As RadListBoxItem In items
            Me.LeftList.Items.Remove(item)
            Me.RightList.Items.Add(item)
        Next
    End Sub


Good luck!

Neo
Oakton IT
Melbourne
0
Mike A
Top achievements
Rank 1
answered on 29 May 2010, 03:03 PM
hello
thanks for your help

i am still getting an error even with your code
here is the error line
Me.LeftList.Items.Remove(item)

here is the error

System.InvalidOperationException was unhandled
  Message="Data bound items can not be removed. Remove items from the data source instead."
  Source="Telerik.WinControls.UI"
  StackTrace:
       at Telerik.WinControls.UI.UIElements.ListBox.Data.RadListBoxItemOwnerCollection.OnRemove(Int32 index, Object value)    at System.Collections.CollectionBase.RemoveAt(Int32 index)    at Telerik.WinControls.RadItemCollection.Remove(RadItem value)    at RetailManagementSystem.AssignAccount.SelectBtu_Click(Object sender, EventArgs e) in D:\Retail_Management_System\majd\AssignAccount.vb:line 84    at System.Windows.Forms.Control.OnClick(EventArgs e)    at Telerik.WinControls.RadControl.OnClick(EventArgs e)    at Telerik.WinControls.UI.RadButton.ButtonElement_Click(Object sender, EventArgs e)    at Telerik.WinControls.RadItem.OnClick(EventArgs e)    at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)    at Telerik.WinControls.RadItem.DoClick(EventArgs e)    at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)    at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)    at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)    at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)    at System.Windows.Forms.Control.WndProc(Message& m)    at Telerik.WinControls.RadControl.WndProc(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.UnsafeNativeMethods.DispatchMessageW(MSG& msg)    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)    at RetailManagementSystem.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    at System.Threading.ThreadHelper.ThreadStart()
  InnerException:


thanks







0
Mike A
Top achievements
Rank 1
answered on 29 May 2010, 03:12 PM
also when i remove the Remove.item line i get the same error i started with


thanks
0
Neo Cortex
Top achievements
Rank 1
answered on 31 May 2010, 12:45 AM
Hi Mike,

Direct item modification in .Net and Telerik lists is incompatible with data binding.

i.e. the line: 

                Me.RightList.Items.Add(item)

is incompatible with Data Binding.

If you have any trouble with data binding then it is best to stick with item level manipulation of lists.

Here's an awesome page describing the use of data binding:
    
                http://www.akadia.com/services/dotnet_databinding.html

Best,
Neo
0
Victor
Telerik team
answered on 03 Jun 2010, 09:22 AM
Hi Guys,

The first exception is usually encountered when code on another thread throws an exception. The thrown exception is wrapped in a TargetInvocationException, so in order to see what is really going on you need to look at the InnerException property of the TargetInvocationException.

The fact that RadListBox throws an InvalidOperationException when trying to remove items from it in a data binding scenario is deliberate. RadListBox is not an editable control it serves only as a visual representation of the data it is bound to. In order to remove items from it, you will have to ask the data source to remove the item you need and RadListBox will refresh itself. Please note that the exception text suggests this as well.

Write again if you need further assistance.

Regards,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mike A
Top achievements
Rank 1
answered on 04 Jun 2010, 03:54 PM
hello
I am not sure what to do!!!! I load the listbox from the databases and here is my code



    Public Shared Sub FillListBox2(ByVal dropname As Telerik.WinControls.UI.RadListBox, ByVal tablename As String, ByVal first As String, ByVal displaymember As String, ByVal valuemember As String, Optional ByVal Whereline As String = "")

        Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT 'No ' + Cast(" & first & " As varchar(20)) + ':  >>  $' + Cast(" & displaymember & " As varchar(20))   AS " & displaymember & ", " & valuemember & "  FROM " & tablename & " " & Whereline & " ", Common.GetConnection)
        Dim ds As New DataSet

        da.Fill(ds, tablename)

        dropname.DataSource = ds.Tables(tablename).DefaultView
        dropname.DisplayMember = displaymember
        dropname.ValueMember = valuemember

        da.Dispose()
        ds.Dispose()
    End Sub


so how do i transfer data between listboxes??? thanks


0
Victor
Telerik team
answered on 10 Jun 2010, 04:47 AM
Hello Mike Elnar,

Thank you for writing.

I am afraid that I can not reproduce the issue that you are experiencing.
From the code you provided the only thing I see is that you are disposing your DataSet object while you are still using the DataTable in it. Please post a support ticket and attach your application so that we can debug it and provide a solution.

I am looking forward to your reply.

Best wishes,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Mike A
Top achievements
Rank 1
Answers by
Neo Cortex
Top achievements
Rank 1
Mike A
Top achievements
Rank 1
Victor
Telerik team
Share this question
or