Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:56:08+00:00 2026-06-14T16:56:08+00:00

How i can moving object( that is include name and id) from listbox to

  • 0

How i can moving object( that is include name and id) from listbox to another listbox and save it?
i wrote this:

 if (lstActivity.SelectedIndex != -1)
            {

                int intSelectedIndex = lstActivity.SelectedIndex;
                if (intSelectedIndex >= 0)
                {

 listbox.Items.Add(((Parking_Services.Activity)lstActivity.SelectedItem).ActivityName);

                    lstActivity.Items.RemoveAt(intSelectedIndex);
                }
            }

it is worked but when i want save this (after clicked button), it get exception : ” can not cast syste.string to (Parking_Services.Activity).”

  private void btnSave_Click(object sender, EventArgs e)
        {
            int intActivityID;
            Parking_Services.Service1 ii = new Parking_Services.Service1();
            for (int i = 0; i <= listbox.Items.Count; i++)                                            //save item from listbox is wrong
            {
                intActivityID = ((Parking_Services.Activity)listbox.Items[i]).ActivityID;
                string strMessage = ii.AllowUserActivityByType(intUserTypeID, intActivityID, FrmLogin.intUserId);

            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:56:09+00:00Added an answer on June 14, 2026 at 4:56 pm

    The line…

    intActivityID = ((Parking_Services.Activity)listbox.Items[i]).ActivityID;
    

    …fails, because the items in listbox are Strings and not Parking_Services.Activitys. And they are Strings because, you add Strings in the line…

    listbox.Items.Add(((Parking_Services.Activity)lstActivity.SelectedItem).ActivityName);
    

    I suppose the ActivityName property is a String. So there is a design error in either of those two lines.


    I suggest the following fix: Add the whole Parking_Services.Activity objects to listbox…

    listbox.Items.Add((Parking_Services.Activity)lstActivity.SelectedItem);
    

    …and override ToString() in the Parking_Services.Activity class, so listbox displays them correctly:

    public class Activity
    {
        ...
    
        public override string ToString()
        {
            return ActivityName;
        }
    }
    

    A ListBox always calls ToString() on the objects passed to it, when painting their list entries. So, by overriding ToString(), you can control how your Parking_Services.Activitys are displayed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When moving an object from one collection to another and when cascade is set
In wpf how can i prevent user from moving the windows by dragging the
I know that you can show current GPS moving location on map with WP7
I want to create an object that moves (like people are moving or elastic
Is it possible to copy a function (or any object for that matter) from
how can i perform animation on my moving object.... and how can i control
I have an object called point that I can move around the screen with
I have a camera object that I have put together from reading on the
how can i create a moving image object for an android game application.and also
In my developments I am slowly moving from an object-oriented approach to interface-based-programming approach.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.