Click here to Skip to main content
15,910,872 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
HI
Please assist in re-write the following code (especially the if statement part) such that it uses a while loop to check if the enough "delegates" were captured and populates on list box lstDelegates:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ingwenyama
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string OrganiserName, IDNumber, Contact, Nationality;
        int NumDays, NumDelegates;
       //int NumD;
        private void btnCapture_Click(object sender, EventArgs e)
        {

            populateDelegates(4);
            //radImbizo.Checked = false;
            //NumDelegates++;

        }

        private void radImbizo_CheckedChanged(object sender, EventArgs e)
        {
            txtDelegate.Enabled = true;

        }

        public int numDelegate(int num)
        {
            return NumDelegates = NumDelegates + 1;
        }

        public void populateDelegates(int maxDelegates)
        {
            lstDelegates.Items.Add(txtDelegate.Text);
            txtDelegate.Enabled = false;
            //NumDelegates = 0;
            if (NumDelegates < maxDelegates)
            {
                txtDelegate.Enabled = true;
                numDelegate(NumDelegates);
                txtDelegate.Clear();
                txtDelegate.Focus();

                //
            }
            else
            {
                txtDelegate.Enabled = false;
                btnCapture.Enabled = false;
            }
        }

       

}
Posted
Comments
Sicppy 13-Aug-13 16:56pm    
How and where do you want it done? Do you want it to loop through and progressively add more delegates? Or do you want it to just keep checking the variable and wait until it has enough?
ZurdoDev 13-Aug-13 17:01pm    
Where are you stuck? Why can't you do it?
Sergey Alexandrovich Kryukov 13-Aug-13 17:24pm    
Any problems?
—SA

1 solution

Where is the text for Delegates coming from? Your code is just adding one Delegate to the list. This method isn't needed:
C#
numDelegate(int num)

Your while loop would be like this:
C#
private void buttonCapture_Click(object sender, EventArgs e)
        {
            populateDelegates(4);
        }

        private void populateDelegates(int maxDelegates)
        {
            this.numDelegates = 0;
            this.listBox1.Items.Clear();
            while (numDelegates < maxDelegates)
            {
                this.listBox1.Items.Add("Delegate " + numDelegates.ToString());
                numDelegates++;
            }

        }
 
Share this answer
 
v2
Comments
Member 10207759 14-Aug-13 1:30am    
Thanks a million

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900