Click here to Skip to main content
16,012,061 members
Home / Discussions / C#
   

C#

 
GeneralRe: Winsock Library Recommendation? Pin
Richard Andrew x644-Mar-10 11:31
professionalRichard Andrew x644-Mar-10 11:31 
GeneralRe: Winsock Library Recommendation? Pin
snorkie4-Mar-10 16:30
professionalsnorkie4-Mar-10 16:30 
AnswerRe: Winsock Library Recommendation? Pin
Ennis Ray Lynch, Jr.4-Mar-10 11:41
Ennis Ray Lynch, Jr.4-Mar-10 11:41 
Questionfiles name of a directory in a lable one by one Pin
tanweer4-Mar-10 9:11
tanweer4-Mar-10 9:11 
AnswerRe: files name of a directory in a lable one by one Pin
AspDotNetDev4-Mar-10 9:35
protectorAspDotNetDev4-Mar-10 9:35 
Questionloop in service. Pin
noamtzu004-Mar-10 8:29
noamtzu004-Mar-10 8:29 
AnswerRe: loop in service. Pin
Dave Kreskowiak4-Mar-10 9:07
mveDave Kreskowiak4-Mar-10 9:07 
QuestionString Arrays Pin
Darrall4-Mar-10 5:01
Darrall4-Mar-10 5:01 
Can anybody tell me what is wrong with my logic in the following code? I am trying to get a string array to take the names of projects entered one at a time from a text box. I have to be able to add to, delete from and sort the list alphabetically.

I can't use SQL because most of the time this program will be used offline.

When I build and run it I am getting no errors until the button click after entering the text in the box.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace Construction_Survey_Layout
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        // PN is the index. I didn't set it to 0 because I want it to retain it's value
        // It is at 0 the first time run.
        public int PN;

        private void btnNew_Click(object sender, EventArgs e)
        {
            ArrayList Projects = new ArrayList();            
            // The error was directed at PN here.
            Projects[PN] = textBoxAddNew.ToString();

            Projects.Add(Projects[PN]);
                                    
            textBoxAddNew.Clear();

            Projects.Sort();

            for(int ctr = 0; ctr <= PN; ctr++)
            {
                listBox1.Items.Add(Projects[ctr]);                
            }
            PN++;
            
            // The following is the error message I got after entering a Project Name in the text box
            // and clicked the Add New button:
            //Index was out of range. Must be non-negative and less than the size of the collection.
            //  Parameter name: index
        }

        
    }
}

AnswerRe: String Arrays Pin
PIEBALDconsult4-Mar-10 5:08
mvePIEBALDconsult4-Mar-10 5:08 
GeneralRe: String Arrays Pin
Darrall4-Mar-10 5:53
Darrall4-Mar-10 5:53 
GeneralRe: String Arrays Pin
PIEBALDconsult4-Mar-10 11:35
mvePIEBALDconsult4-Mar-10 11:35 
GeneralRe: String Arrays Pin
Darrall4-Mar-10 11:56
Darrall4-Mar-10 11:56 
AnswerRe: String Arrays Pin
harold aptroot4-Mar-10 5:17
harold aptroot4-Mar-10 5:17 
GeneralRe: String Arrays Pin
Darrall4-Mar-10 6:01
Darrall4-Mar-10 6:01 
AnswerRe: String Arrays [modified] Pin
OriginalGriff4-Mar-10 5:35
mveOriginalGriff4-Mar-10 5:35 
GeneralRe: String Arrays Pin
Darrall4-Mar-10 5:58
Darrall4-Mar-10 5:58 
Questioncombobox height? Pin
Pawan Kiran4-Mar-10 3:53
Pawan Kiran4-Mar-10 3:53 
QuestionRe: combobox height? Pin
Eddy Vluggen4-Mar-10 4:16
professionalEddy Vluggen4-Mar-10 4:16 
AnswerRe: combobox height? Pin
Pawan Kiran4-Mar-10 4:26
Pawan Kiran4-Mar-10 4:26 
AnswerRe: combobox height? Pin
Luc Pattyn4-Mar-10 4:19
sitebuilderLuc Pattyn4-Mar-10 4:19 
AnswerRe: combobox height? Pin
Covean4-Mar-10 4:39
Covean4-Mar-10 4:39 
GeneralRe: combobox height? [modified] Pin
Pawan Kiran4-Mar-10 18:49
Pawan Kiran4-Mar-10 18:49 
GeneralRe: combobox height? Pin
Covean4-Mar-10 20:41
Covean4-Mar-10 20:41 
GeneralRe: combobox height? [modified] Pin
Pawan Kiran4-Mar-10 21:50
Pawan Kiran4-Mar-10 21:50 
GeneralRe: combobox height? Pin
Covean4-Mar-10 22:31
Covean4-Mar-10 22:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.