Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,069 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,590 people online right now. Registration is fast and FREE... Join Now!




how to load array + for loop in a listbox

 
Reply to this topicStart new topic

how to load array + for loop in a listbox

gilbert
9 Apr, 2008 - 07:30 PM
Post #1

D.I.C Head
**

Joined: 18 Mar, 2008
Posts: 81


My Contributions
How do I get a listbox to display an array with a for loop...well, what I guess I'm asking is, I created the listbox in the IDE but I don't exactly know where to put the for loop, where is the for loop to be placed?
User is offlineProfile CardPM
+Quote Post

Jayman
RE: How To Load Array + For Loop In A Listbox
9 Apr, 2008 - 08:30 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
After you declare the array, but before you need it displayed to the user.

Your question is very general, the answer depends on when you have data in the array and when you need it to be visible to the user.
User is online!Profile CardPM
+Quote Post

gilbert
RE: How To Load Array + For Loop In A Listbox
10 Apr, 2008 - 05:07 PM
Post #3

D.I.C Head
**

Joined: 18 Mar, 2008
Posts: 81


My Contributions
the problem is idk where to put the array...everytime i try to put the array and the for loop somewhere i get 13 or more errors
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Load Array + For Loop In A Listbox
10 Apr, 2008 - 05:10 PM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8525
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Post the code you're using. Without seeing that we have absolutely no idea what you're doing wrong
code.gif smile.gif
User is online!Profile CardPM
+Quote Post

gilbert
RE: How To Load Array + For Loop In A Listbox
10 Apr, 2008 - 05:13 PM
Post #5

D.I.C Head
**

Joined: 18 Mar, 2008
Posts: 81


My Contributions
CODE
namespace WindowsApplication1
{
    partial class Form1
    {

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.listBox2 = new System.Windows.Forms.ListBox();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            //
            // listBox1
            //
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Location = new System.Drawing.Point(6, 46);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(120, 108);
            this.listBox1.TabIndex = 0;
            this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
            //
            // listBox2
            //
            this.listBox2.FormattingEnabled = true;
            this.listBox2.Location = new System.Drawing.Point(142, 46);
            this.listBox2.Name = "listBox2";
            this.listBox2.Size = new System.Drawing.Size(120, 108);
            this.listBox2.TabIndex = 1;
            this.listBox2.SelectedIndexChanged += new System.EventHandler(this.listBox2_SelectedIndexChanged);
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(76, 215);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(134, 23);
            this.button1.TabIndex = 2;
            this.button1.Text = "Perform Conversion";
            this.button1.UseVisualStyleBackColor = true;
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(138, 25);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(60, 13);
            this.label1.TabIndex = 3;
            this.label1.Text = "Convert To";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(3, 25);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(70, 13);
            this.label2.TabIndex = 4;
            this.label2.Text = "Convert From";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(141, 192);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(0, 13);
            this.label3.TabIndex = 5;
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(141, 175);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(37, 13);
            this.label4.TabIndex = 6;
            this.label4.Text = "Result";
            //
            // label5
            //
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(32, 175);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(86, 13);
            this.label5.TabIndex = 7;
            this.label5.Text = "Value to Convert";
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(35, 189);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 20);
            this.textBox1.TabIndex = 8;
            //
            // groupBox1
            //
            this.groupBox1.Controls.Add(this.listBox2);
            this.groupBox1.Controls.Add(this.listBox1);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(12, 12);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(268, 160);
            this.groupBox1.TabIndex = 9;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Conversion";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.ListBox listBox1;
        this.listBox1.Items.AddRange(new object[]
        {"Inches", "Feet", "Yard", "Millimeter", "Centimeter", "Meter"});

        private System.Windows.Forms.ListBox listBox2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.GroupBox groupBox1;

    }
}



that's 14 errors
User is offlineProfile CardPM
+Quote Post

Jayman
RE: How To Load Array + For Loop In A Listbox
10 Apr, 2008 - 05:24 PM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Create the array inside the Load event and then put the For loop after it, also inside the Load event.

I am assuming that you want it to populate the ListBox during Form load. Is that correct?

Also, post the error messages that you are getting.
User is online!Profile CardPM
+Quote Post

gilbert
RE: How To Load Array + For Loop In A Listbox
10 Apr, 2008 - 05:37 PM
Post #7

D.I.C Head
**

Joined: 18 Mar, 2008
Posts: 81


My Contributions
that's the main gist of what i'm trying to do...but i'm new to this and idk WTF the load event is or where to find it
the error messages all had to do with the System.whatever not complying with something
User is offlineProfile CardPM
+Quote Post

gilbert
RE: How To Load Array + For Loop In A Listbox
10 Apr, 2008 - 06:38 PM
Post #8

D.I.C Head
**

Joined: 18 Mar, 2008
Posts: 81


My Contributions
HOW DO I GET THE ARRAY TO APPEAR IN THE LISTBOX!!!! PLEASE!!!!
User is offlineProfile CardPM
+Quote Post

Jayman
RE: How To Load Array + For Loop In A Listbox
10 Apr, 2008 - 06:49 PM
Post #9

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Double click on your Form in the Designer, this will open the code window with the Load Event. Now put the code inside the event and your good to go.

Copy and paste your error messages, so we can see exactly what they are. Telling us that it is "System.whatever not complying with something", does not give any useful information.

In the future avoid typing in all caps, it is considered yelling.
User is online!Profile CardPM
+Quote Post

gilbert
RE: How To Load Array + For Loop In A Listbox
10 Apr, 2008 - 06:55 PM
Post #10

D.I.C Head
**

Joined: 18 Mar, 2008
Posts: 81


My Contributions
i was screaming for help....and when i double clicked the boxes it ended up being "selectedIndexChanged" but i found the load event and now there are no error messages but i can't see the strings when i test it
User is offlineProfile CardPM
+Quote Post

Jayman
RE: How To Load Array + For Loop In A Listbox
11 Apr, 2008 - 07:49 AM
Post #11

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
The reason you got the SelectedIndexChanged event is because you double clicked on a control. You just want to double click the Form itself to get the Load event, not a control on the Form.

Post your current code and we will help get it up and running.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:56PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month