Exemplo n.º 1
0
        //private void CheckValueCell_LEave(object sender, DataGridViewCellEventArgs e)
        //{
        //    if (e.ColumnIndex >= 0 && e.RowIndex != -1)
        //    {

        //        int roind = e.RowIndex;
        //        //if (e.rowindex > 0)
        //        //    roind;
        //        object currControl = null; ;

        //        DataGridViewCell currControl1 = (DataGridViewCell)DGVMatContainer[e.ColumnIndex, roind];
        //        if (currControl1.GetType() == typeof(DataGridViewTextBoxCell))
        //            currControl = (DataGridViewTextBoxCell)currControl1;
        //        if (currControl1.GetType() == typeof(DataGridViewCheckBoxCell))
        //            currControl = (DataGridViewCheckBoxCell)currControl1;
        //        if (currControl1.GetType() == typeof(DataGridViewComboBoxCell))
        //            currControl = (DataGridViewComboBoxCell)currControl1;
        //        string currvaluecell = Convert.ToString(DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Value);
        //        if (numericFieldMoreThanZeroTB.Contains(DGVMatContainer.Columns[e.ColumnIndex].Name))
        //        {
        //            var isNumeric = Int32.TryParse(currvaluecell, out Int32 n);
        //            if (!isNumeric)
        //            {

        //                //MessageBox.Show("Invalid number", "Wrong Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //                //currControl.EditedFormattedValue = String.Empty;
        //                DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Style = csOrange;
        //               // DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Value = "0";



        //            }
        //            else
        //                if (n < 0)
        //            {
        //                // MessageBox.Show("number  must be more than 0", "Wrong Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //                //currControl.EditedFormattedValue = String.Empty;
        //                DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Style = csOrange;
        //                // DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Value = "0";
        //                // SetValue(sender, e);

        //            }
        //            else
        //            {
        //                DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Style.BackColor = Color.White;

        //            }
        //        }
        //        if (decimaFieldMoreThanZeroTB.Contains(DGVMatContainer.Columns[e.ColumnIndex].Name))
        //        {
        //            var isNumeric = decimal.TryParse(currvaluecell.Trim(), out decimal n);
        //            if (!isNumeric)
        //            {
        //                //MessageBox.Show("Invalid number", "Wrong Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //                // currControl.EditedFormattedValue = String.Empty;
        //                DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Style = csOrange;
        //                // DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Value = "0";



        //                // SetValue(sender, e);


        //            }
        //            else
        //                if (n < 0)
        //            {
        //                // MessageBox.Show("number  must be more than 0", "Wrong Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //                //currControl.Value = String.Empty;
        //                DGVMatContainer.Rows[roind ].Cells[e.ColumnIndex].Style = csOrange;
        //                //DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Value = "0";
        //                //SetValue(sender, e);

        //            }
        //            else
        //            {
        //                DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Style = csWhite;


        //            }
        //        }


        //        if (notRequired.Contains(DGVMatContainer.Columns[e.ColumnIndex].Name))
        //        {
        //            DGVMatContainer.Rows[roind].Cells[e.ColumnIndex].Style = csWhite;

        //        }

        //    }
        //}

        private void Change_BGColor(object sender, DataGridViewCellEventArgs e)
        {
            DGVMatContainer.Rows[e.RowIndex].Cells[e.ColumnIndex].Style = csgray;
            {
                if (DGVMatContainer.CurrentCell.ColumnIndex == 3)  //example-'Column index=4'
                {
                    DGVMatContainer.BeginEdit(true);
                }
            }
        }
Exemplo n.º 2
0
        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");
            }
        }