Johan Adler
Johan Adler

Reputation: 13

if text box array how to add to listbox

I'm having a slight issue with my program. I'm a first year student and am trying to make a program on flight reservation.

if (txtSeat.Text == "1")
{
   btnRowOneSeatOne.BackColor = Color.Red;
   goodMessage += "You Selected Row One and Seat One";
}

So, this basically goes down for all 15 seats in the same manner. I have a textbox and if you type numbers from 1-15 the seat will button turn red.

I also did pretty much the same thing in removing the customer. As followed

This was in the remove button handle

if (txtRemove.Text == "1")
{
       btnRowOneSeatOne.BackColor = Color.Black;
}

I haven't started on an array yet. Basically for that I have a text box once the number is enter it should store it in the array.

I believe this should be the coding

seatNum = int.Parse(txtSeat.Text);
bool availability = false;

for (int s = 0; s < seats.Length; s++)
{
    seats[s] = seatNum
    availability = true;
    break;
}
if (availability == true)
{
}

I believe this should store the seat in array. I've tried many different ways, but couldn't seem to find away. This is an assignment for a class FYI.

Upvotes: 1

Views: 475

Answers (1)

Muthulakshmi S
Muthulakshmi S

Reputation: 32

          int seatnum = int.Parse(textBox1.Text);
         Seat = new int[15];
        if (textBox1.Text != "")
        {
            Seat[seatnum - 1] = seatnum;
        }
        for (int i = 0; i < 15; i++)
        {
            if (Seat[i] != 0)
            {
                listBox1.Items.Add(textBox1.Text);
            }
        }

Upvotes: 1

Related Questions