// Creat a new tab with the specific car data private void newTab( Cars car) { bool status = false; // If the car was already open in a tab, this will finde the specific tab and show foreach (TabPage page in tabControl1.Controls) { if (page.Name.Equals(car.ID)) { status = true; this.tabControl1.SelectTab(page); break; } } if(status==false){ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Buy)); this.tabPage2 = new System.Windows.Forms.TabPage(); this.tabControl1.SuspendLayout(); this.tabPage2.SuspendLayout(); this.SuspendLayout(); // tabControl1 // this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Location = new System.Drawing.Point(13, 13); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(638, 349); this.tabControl1.TabIndex = 1; // tabPage2 // this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.tabPage2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("tabPage1.BackgroundImage"))); string brand = car.brand + " "; this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = car.ID; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); this.tabPage2.Size = new System.Drawing.Size(638, 349); this.tabPage2.TabIndex = 1; this.tabPage2.Text = brand; this.tabPage2.UseVisualStyleBackColor = true; CreateButton("I would like to Buy", 300, 280, this.tabPage2, car.ID); // // Car Data Label("Car Data", 6, 8, 15, this.tabPage2); //ADATOK Label("Brand", 40, 50, 9, this.tabPage2); Label(car.brand, 140, 50, 9, this.tabPage2); Label("Type", 40, 70, 9, this.tabPage2); Label(car.type, 140, 70, 9, this.tabPage2); Label("Year", 40, 90, 9, this.tabPage2); Label(car.year, 140, 90, 9, this.tabPage2); Label("Price", 40, 110, 9, this.tabPage2); Label(car.price, 140, 110, 9, this.tabPage2); Picture(this.tabPage2, car.pic); this.tabControl1.SelectTab(this.tabPage2); } }
// When the user choose a car this method open a new tab with the cars data (Search Tab) private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { DataGridView dgw = (DataGridView)sender; Cars car = new Cars(); car.ID = dgw.Rows[e.RowIndex].Cells[0].Value.ToString(); car.brand = dgw.Rows[e.RowIndex].Cells[1].Value.ToString(); car.type = dgw.Rows[e.RowIndex].Cells[2].Value.ToString(); car.year = dgw.Rows[e.RowIndex].Cells[4].Value.ToString(); car.status = dgw.Rows[e.RowIndex].Cells[5].Value.ToString(); car.price = dgw.Rows[e.RowIndex].Cells[6].Value.ToString(); car.pic = dgw.Rows[e.RowIndex].Cells[8].Value.ToString(); newTab(car); }