private void Form1_Load(object sender, EventArgs e) { //setup the columns to be added. dataGridView1.ColumnCount = 4; //Set the columns name dataGridView1.Columns[0].Name = "Item"; dataGridView1.Columns[1].Name = "Price"; dataGridView1.Columns[2].Name = "Quantity"; dataGridView1.Columns[3].Name = "Sub-Total"; //Set a value to be added in a row //adding rows in the datagridview dataGridView1.Rows.Add(row); //Set a value to be added in a row //adding rows in the datagridview dataGridView1.Rows.Add(row); //Set a value to be added in a row //adding rows in the datagridview dataGridView1.Rows.Add(row); //Set a value to be added in a row //adding rows in the datagridview dataGridView1.Rows.Add(row); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { dtg = dataGridView1; txtProduct.Text = dtg.CurrentRow.Cells[0].Value.ToString(); txtPrice.Text = dtg.CurrentRow.Cells[1].Value.ToString(); txtQauntity.Text = dtg.CurrentRow.Cells[2].Value.ToString(); txtSubtotal.Text = dtg.CurrentRow.Cells[3].Value.ToString(); }