Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Trouble modifying text after copying items between listboxes

Reply
Thread Tools

Trouble modifying text after copying items between listboxes

 
 
AlBruAn
Guest
Posts: n/a
 
      07-16-2007
I have an application under development that contains, among other controls,
two listboxes containing Available Tasks and Assigned Tasks. Let's say one
of the Available Tasks is "Send Letter" and the user wishes to copy it over
to the Assigned Tasks listbox; in that case, it's a simple matter of
executing the following line of code:


lbAssignedTasks.Items.Add(lbAvailableTasks.Items(l bAvailableTasks.SelectedIndex()))

Let's further state that a few other tasks are assigned and then the user
wants to assign sending a follow-up letter by again selecting "Send Letter".
In this case, I want to modify the first instance of "Send Letter" to read
"Send Letter - 1" and modify the second instance of "Send Letter" to read
"Send Letter - 2". I've attempted to set the text for the added instance by
setting it as follows:

lbAssignedTasks.Items(lbAssignedTasks.Items.Count - 1).Text =
lbAssignedTasks.Items(lbAssignedTasks.Count - 1).Text + " - " + CType(2,
String)

and I've attempted to set the text for the first instance by setting it as
follows:

lbAssignedTasks.Items(i).Text = lbAssignedTasks.Items(i).Text + " - " +
CType(1, String)

The value for i in both statements is determined by stepping through the
list of Assigned Tasks working from the last item to the first until I find
an item that .Contains("Send Letter").

As far as I can tell, that part seems to be working correctly, but modifying
the text value for an item in the Assigned Tasks listbox is somehow being
"sent back" to the Available Tasks listbox and modifying the text for "Send
Letter" to also be "Send Letter - 2".

Why is this happening and is there a workaround solution to my problem?
 
Reply With Quote
 
 
 
 
AlBruAn
Guest
Posts: n/a
 
      07-17-2007
You're answer worked perfectly. The only other thing I had to do was grab
the SelectedValue of the Available Task that was selected and reset the Value
property of the newly-assigned task after assigning it.


"David R. Longnecker" wrote:

> If I'm understanding your question, I believe the issue is because your objects
> are reference types--and when you change one, it changes them all.
>
> > lbAssignedTasks.Items.Add(lbAvailableTasks.Items(l bAvailableTasks.SelectedIndex()))

>
> Here, your AssignedTasks list box is adding a the reference to the selected
> ListItem in AvailableTasks; not creating a new item. You could try newing
> up a ListItem before you add it, creating a new reference. I have the text
> change (the second line of code) just to verify that it changes only in one
> place--not both.
>
> Dim newItem As New ListItem(DropDownList1.SelectedItem.Text, DropDownList1.SelectedValue)
> newItem.Text = "Moved to Assigned Tasks - " + newItem.Text
> DropDownList2.Items.Add(newItem)
>
> HTH.
>
> -dl
>
> --
> David R. Longnecker
> http://blog.tiredstudent.com
>
> > I have an application under development that contains, among other
> > controls, two listboxes containing Available Tasks and Assigned Tasks.
> > Let's say one of the Available Tasks is "Send Letter" and the user
> > wishes to copy it over to the Assigned Tasks listbox; in that case,
> > it's a simple matter of executing the following line of code:
> >
> > lbAssignedTasks.Items.Add(lbAvailableTasks.Items(l bAvailableTasks.Sele
> > ctedIndex()))
> >
> > Let's further state that a few other tasks are assigned and then the
> > user wants to assign sending a follow-up letter by again selecting
> > "Send Letter". In this case, I want to modify the first instance of
> > "Send Letter" to read "Send Letter - 1" and modify the second instance
> > of "Send Letter" to read "Send Letter - 2". I've attempted to set the
> > text for the added instance by setting it as follows:
> >
> > lbAssignedTasks.Items(lbAssignedTasks.Items.Count - 1).Text =
> > lbAssignedTasks.Items(lbAssignedTasks.Count - 1).Text + " - " +
> > CType(2, String)
> >
> > and I've attempted to set the text for the first instance by setting
> > it as follows:
> >
> > lbAssignedTasks.Items(i).Text = lbAssignedTasks.Items(i).Text + "
> > - " + CType(1, String)
> >
> > The value for i in both statements is determined by stepping through
> > the list of Assigned Tasks working from the last item to the first
> > until I find an item that .Contains("Send Letter").
> >
> > As far as I can tell, that part seems to be working correctly, but
> > modifying the text value for an item in the Assigned Tasks listbox is
> > somehow being "sent back" to the Available Tasks listbox and modifying
> > the text for "Send Letter" to also be "Send Letter - 2".
> >
> > Why is this happening and is there a workaround solution to my
> > problem?
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Related listboxes and items mohaaron@gmail.com ASP .Net 0 10-30-2007 04:37 PM
moving items between two listboxes ASPirant ASP .Net Web Controls 0 11-22-2005 08:07 AM
Moving items between listboxes on client side florin ASP .Net 2 03-04-2005 01:31 PM
Pass Listitem between Listboxes =?Utf-8?B?U2NvdXRMZWU=?= ASP .Net 0 09-20-2004 01:43 PM
Switching items between listboxes, and letting .net realize it. Ryan Ternier ASP .Net 1 07-25-2004 05:18 PM



Advertisments