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 6696957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:24:09+00:00 2026-05-26T06:24:09+00:00

i want from my program to select a listbox item and then update it.i

  • 0

i want from my program to select a listbox item and then update it.i have a list ecoItems.Eco is a class with 2 store variables,one string and one double variable.SetEcoValues is a set Method take two values,one string and one double.i try this code but don’t change anything.any suggestions?

         private void Update_Click(object sender, EventArgs e)
    {


            Eco y;
            y = ecoItems.ElementAt<Eco>(listBox1.SelectedIndex);
            y.SetEcoValues(textBox1.Text,Convert.ToDouble(textBox2.Text));
            listBox5.Items.Insert(listBox1.SelectedIndex, y);
        }


    }
  • 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-05-26T06:24:10+00:00Added an answer on May 26, 2026 at 6:24 am

    Using your code and what I would guess is your class, I’d do something like this:

    class Eco {
      public Eco() { }
      public void SetEcoValues(string text, double value) {
        Text = text;
        Value = value;
      }
      public string Text { get; set; }
      public double Value { get; set; }
      public override string ToString() {
        if (!String.IsNullOrEmpty(Text)) {
          return Text;
        }
        return base.ToString();
      }
    }
    
    ListView listView1; // initialized somewhere, I presume.
    
    void Update_Click(object sender, EventArgs e) {
      if ((listView1.SelectedItems != null) || (0 < listView1.SelectedItems.Count)) {
        ListViewItem item = listView1.SelectedItems[0];
        Eco y = item.Tag as Eco;
        if (y == null) {
          y = new Eco();
        }
        y.SetEcoValues(textBox1.Text, Convert.ToDouble(textBox2.Text));
        item.Text = y.Text;
        if (item.SubItems.Count < 2) {
          item.SubItems.Add(y.Value.ToString());
        } else {
          item.SubItems[1].Text = y.Value.ToString();
        }
        item.Tag = y;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ability to select code from my program such as dreamweaver or
Hello from an SQL nO0b, I have three Select statements I want to join:
I want to update/create a SharePoint List using InfoPath. So far I have the
I want to write a program from scratch to see the sockets activity, what
When I run the program from IDE (VS2008) it works perfectly. When I want
I want to print columnar output from a ruby program, but in order to
I want to launch a file(a document) from a Java program and phase the
I want to execute a batch file from a java program. I am using
I want to run the following command from a C program to read the
I need to consume an external web service from my VB6 program. I want

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.