Skip to content

Assign a string to the item in listbox

nicia

Asked Sep 4, 2005, 8:20 PM EDT2 answers
Share
LinkedInX
Hi
i am new to c# program and have a problem in dealing with my listbox item. I hope you all can help.

i have a listbox and each item entered wil automatic been assign a string. This string is editable when user click on the edit button(a form will be appear for user to edit). Ok, now my problem is how can i allow the string to assign to the item and how to store back the string (if it had been edited) to the item again.

I am sorry if this question is simple to u all but please help and guide me along, thank u

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi i had just figure out how to do this function but it onli apply to 1 or 2 item. If there many item in the listbox, a run time error will be appear when i click on the edit button(error msg "An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll").

    Below is my coding, can anyone please tell me which part of the my code is wrong. thank u smile

    Form main

    public ArrayList destination = new ArrayList();
    private editForm edit;

    public string getDest(){return this.destination[this.listBoxFile.SelectedIndex].ToString();}

    public void setDest(string path){this.destination[this.listBoxFile.SelectedIndex] = path;}

    public string getCustDest(){return this.destination[this.listBoxFile.SelectedIndex].ToString();}

    public void setCustDest(string path){this.destination[this.listBoxFile.SelectedIndex] = path;}

    private void buttonEdit_Click(object sender, System.EventArgs e){
                this.destination.Add("Application Directory");
                edit = new editForm(this);
                edit.ShowDialog();
    }

    Form edit
    private void information()
    {
        string dest = main.getDest();
        this.comboDest.Text = dest;
        if(dest=="[Custom]")
        {
            this.textDest.Text = main.getCustDest();
        }
        this.textSource.Text = main.link();
    }

    private void comboDest_SelectedIndexChanged(object sender, System.EventArgs e){
        string select = (string)comboDest.SelectedItem;
        main.setDest(select);
                
        if(select == "[Custom]")
        {
            this.textDest.Enabled = true;
            if(this.textDest.TextLength>0)
            {
                main.setCustDest(this.textDest.Text);
                        
            }
        }
        else
        {
            this.textDest.Enabled = false;
        }
    }
    0
  • 0
    Add an item to ListBox, I think. There's no necessarity to have arraylist and listbox, too
    0