I am currently working on a small project. How it works is a passenger must book where he/she wants to sit on plane. Using a DataGridView he/she can pick a seat except in the ilse.
The DataGridView has 7 columns and 5 rows. The ilse is occupying the whole 3rd row so that they cant pick a seat there.
I want to add a passengers details into a cell on the DataGridView and display it in a list box afterwards. I am a bit new to C# so my code will not be working perfectly so please be patient.
Questions: HOW do I add the Passenger to the array and HOW do I change the row and column color of the selected cell after the passenger has been added??
I have the following code:
public Form1()
{
InitializeComponent();
dgvPlane.Rows.Add(5);
dgvPlane.Rows[0].HeaderCell.Value = "1";
dgvPlane.Rows[1].HeaderCell.Value = "2";
dgvPlane.Rows[2].HeaderCell.Value = "3";
dgvPlane.Rows[3].HeaderCell.Value = "4";
dgvPlane.Rows[4].HeaderCell.Value = "5";
for (int k = 0; k < dgvPlane.ColumnCount; k++)
{
dgvPlane[k, 2].Style.BackColor = Color.DarkSlateGray;
}
dgvPlane.ClearSelection();
}
//ADDING THE PASSENGER INTO THE DATAGRIDVIEW
private void btnAddPassenger_Click(object sender, EventArgs e)
{
Passenger _Passenger = new Passenger();
_Passenger.Details = tbName.Text;
_Passenger.wasteSizeCm = Convert.ToDouble(nudWaistSize.Value);
_Passenger.BigToeSizeMm = Convert.ToDouble(nudToeSize.Value);
MessageBox.Show("Passenger Added");
//comboBox1 is the Columns in a drop down for eg. "1", "2", "3", etc.
//comboBox2 is the Rows in a drop down for eg. "A", "B", "C", etc
dgvPlane.Rows[comboBox2].Cells[comboBox1].Value = _Passenger;
for (int k = 0; k < dgvPlane.ColumnCount; k++)
{
//Change the color of the added passenger's cell to indicate that the seat is now taken
//NOTE: [0,0] is there because I'm not sure how to refer to the row and column values
dgvPlane[0,0].Style.BackColor = Color.Goldenrod;
}
//ADDING THE PASSENGER TO THE ARRAY
PassengerList[comboBox1.Value, comboBox2.Value] = _Passenger;
}
And this is simply my class:
namespace WindowsFormsApplication3
{
class Passenger
{
private string mDetails;
private double mWasteSizeCm;
private double mBigToeSizeMm;
public Passenger()
{
mDetails = "";
mWasteSizeCm = 0;
mBigToeSizeMm = 0;
}
public string Details
{
get { return mDetails; }
set { mDetails = value; }
}
public double wasteSizeCm
{
get { return mWasteSizeCm; }
set { mWasteSizeCm = value; }
}
public double BigToeSizeMm
{
get { return mBigToeSizeMm; }
set { mBigToeSizeMm = value; }
}
}
}
ANY help on this will be IMMENSELY appreciated.
J