private void Button1_Click(object sender, EventArgs e) { DGVMatContainer.ClearSelection();//If you want BLWriteMiutes bLWrite = new BLWriteMiutes(); DGVMatContainer.DataSource = bLWrite.GetMateriale_Container(); DGVMatContainer.Rows.OfType <DataGridViewRow>().Last().Selected = true; if (ValidateCurrentRow(DGVMatContainer.Rows.OfType <DataGridViewRow>().Last())) { LBLStatus.Visible = true; LBLStatus.Text = "Updating....."; LBLStatus.Refresh(); bLWrite.InsertMaterialeWithTransaction(0, "", "", "", "", "", "", "", false, "", "", "", ""); DGVMatContainer.DataSource = bLWrite.GetMateriale_Container(); LBLStatus.Visible = false; LBLStatus.Text = "Updating....."; LBLStatus.Refresh(); } else { MessageBox.Show("Impossibile inserire altra riga"); } }
private void New_Row(object sender, DataGridViewRowEventArgs e) { try { DataGridViewRow dvrc = DGVMatContainer.CurrentRow; Dictionary <string, object> keyValuePair = new Dictionary <string, object>(); foreach (DataGridViewCell cell in dvrc.Cells) { //rowValues[cell.ColumnIndex] = cell.Value; if (cell.OwningColumn.Name != "Pericoloso") { keyValuePair.Add(cell.OwningColumn.Name, cell.Value); } else if (cell.GetType() == typeof(DataGridViewCheckBoxCell)) { DataGridViewCheckBoxCell cellB = (DataGridViewCheckBoxCell)cell; if ((bool)cellB.EditedFormattedValue == false) { keyValuePair.Add(cell.OwningColumn.Name, false); cellB.Style = csDisabled; } else { keyValuePair.Add(cell.OwningColumn.Name, true); } } else if (cell.GetType() == typeof(DataGridViewComboBoxCell)) { DataGridViewComboBoxCell cellB = (DataGridViewComboBoxCell)cell; keyValuePair.Add(cell.OwningColumn.Name, cellB.Value); } } object tempValue = null; //passeggero = Convert.ToInt32(rowValues[0]); keyValuePair.TryGetValue("Id_Materiale", out tempValue); Int32 idMateriale = Convert.ToInt32(tempValue); keyValuePair.TryGetValue("Quantita_Materiale", out tempValue); short qtaMateriale = Convert.ToInt16(tempValue); keyValuePair.TryGetValue("Descrizione_Materiale", out tempValue); string descMateriale = Convert.ToString(tempValue); keyValuePair.TryGetValue("Lunghezza_Materiale", out tempValue); string lungMateriale = Convert.ToString(tempValue); keyValuePair.TryGetValue("Altezza_Materiale", out tempValue); string altMateriale = Convert.ToString(tempValue); keyValuePair.TryGetValue("Profondita_Materiale", out tempValue); string profMateriale = Convert.ToString(tempValue); keyValuePair.TryGetValue("Peso_Materiale", out tempValue); string pesoMateriale = Convert.ToString(tempValue); keyValuePair.TryGetValue("Valore_Materiale", out tempValue); string ValoreMateriale = Convert.ToString(tempValue); keyValuePair.TryGetValue("Matricola", out tempValue); string Matricola = Convert.ToString(tempValue); keyValuePair.TryGetValue("Pericoloso", out tempValue); bool pericoloso = Convert.ToBoolean(tempValue); keyValuePair.TryGetValue("UN_Code", out tempValue); string unCode = Convert.ToString(tempValue); keyValuePair.TryGetValue("Classe_Rischio", out tempValue); string classeR = Convert.ToString(tempValue); keyValuePair.TryGetValue("Compatibilita", out tempValue); string compat = Convert.ToString(tempValue); keyValuePair.TryGetValue("Peso_Pericoloso", out tempValue); string pesoPericoloso = Convert.ToString(tempValue); BLWriteMiutes bLWrite = new BLWriteMiutes(); LBLStatus.Visible = true; LBLStatus.Text = "Updating....."; LBLStatus.Refresh(); if (bLWrite.updateMaterialeWithTransaction(idMateriale, qtaMateriale, Matricola, descMateriale, ValoreMateriale, lungMateriale, altMateriale, profMateriale, pesoMateriale, pericoloso, pesoPericoloso, unCode, classeR, compat)) { DGVMatContainer.DataSource = bLWrite.GetMateriale_Container(); DGVMatContainer.CurrentCell = DGVMatContainer.Rows.OfType <DataGridViewRow>().Last().Cells.OfType <DataGridViewCell>().ElementAt(2); //DGVMatContainer.AllowUserToAddRows = false; this.DGVMatContainer.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.CheckValueCell_Changed); this.DGVMatContainer.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.DGVMatContainer_CellEndEdit); LBLStatus.Visible = false; LBLStatus.Text = "Updating....."; LBLStatus.Refresh(); } else { int i = 0; DGVMatContainer.AllowUserToAddRows = false; DGVMatContainer.Rows.OfType <DataGridViewRow>().Last().Selected = true; this.DGVMatContainer.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.CheckValueCell_Changed); MessageBox.Show("Check reuqired"); return; } } catch (Exception ex) { } }