Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2005

Tip: Looking for answers? Try searching our database.

adding items to listbox with extra data similar to databinding to dataview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TS - 15 Feb 2005 15:43 GMT
since you can't change items in a listbox that is databound, i have to add &
remove items using its items collection. The thing about this is that with
databinding, each item in the list can hold all the info for a particular
datarowview and can be accessed by converting the list item back to this
object.

The real thing i need to do is be able to have the list item's text
displayed correctly, then behind the scenes, i need to be able to access an
ID field from the data record associated with the item so that i can then do
an update to the db with the selected items of the list.

How do i save this extra data without databinding?

thanks
TS - 15 Feb 2005 22:00 GMT
Note: i have a dual listbox and i need to first populate the left list box
from data.

The user can select an item from the left box and click button to move it to
right box, and the item needs to be removed from the left box. After the
user is satisfied, they hit submit, and I want to be able to do something
like the following:

Loop thru each selected item and get its value and update the corresponding
record in DB

foreach (object listitem in list_right.selecteditems)
{
   //Ssave value to DB
   SqlHelper.ExecuteNonQuery(Configuration.ConnectionString,
"spUpdateApplicantByDLN", listitem)
}

First of all i don't know how to add a value to a listitem, then i don't
know how to get it out later. Since i haven't seen how to do it anywhere i'm
guessing it can't be done.

So how do i accomplish what is need to ?

thanks again

> since you can't change items in a listbox that is databound, i have to add &
> remove items using its items collection. The thing about this is that with
[quoted text clipped - 10 lines]
>
> thanks
"Jeffrey Tan[MSFT]" - 16 Feb 2005 03:26 GMT
Hi TS,

Thanks for your posting!!

I am not sure if your first post and the follow up reply point to the same
issue. For the seond issue, I think we may just loop through the selected
items collection of the left listbox, then add each selected item in the
right listbox, then, we may remove the selected item from the left listbox.
Sample code lists below:
for(int i=0;i<this.listBox1.SelectedItems.Count ;i++)
{
    this.listBox2.Items.Add(this.listBox1.SelectedItems[i]);
    this.listBox1.Items.Remove(this.listBox1.SelectedItems[i]);
}

For your first post issue, I am not sure I understand you well. Actually,
ListBox's value and display member concept only make sense for databinding
senario. If we add the items through code without databinding, there are
only items, without the concept of value member and display member. In
databinding senario, the listbox's value member usually binds to the ID key
field of datasource, while displaymember property usually binds to a string
display datacolumn. So, for selected items, we may just use the
SelectedValue property of ListBox to retrieve the associated ID value of
currently selected text item. So we should have no problem of retrieving
the ID field of underlying datasource.

Hope this helps, if I misunderstand you, please feel free to tell me, I
will work with you. Thanks
===========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.