Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

datagridview control

$
0
0

i make a form to record a values but i need

  1. control on a cell to check a datatype and if empty
  2. control a record if some cells empty
  3. check if cell[7] "From" or cell[8]"To" not null and cell[9]"Comment" is null

this is the code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MBLsService.Forms
{
    public partial class ReferanceRangesFRM : Form
    {
        int i;
        public ReferanceRangesFRM()
        {
            InitializeComponent();
        }

        private void ReferanceRangesFRM_Load(object sender, EventArgs e)
        {
            ReferanceRangeDGV.Rows.Add(10);
            ReferanceRangeDGV.Columns[0].ValueType = typeof(decimal);
            ReferanceRangeDGV.Columns[1].ValueType = typeof(decimal);
            ReferanceRangeDGV.Columns[2].ValueType = typeof(decimal);
            ReferanceRangeDGV.Columns[3].ValueType = typeof(decimal);
            ReferanceRangeDGV.Columns[4].ValueType = typeof(decimal);
            ReferanceRangeDGV.Columns[5].ValueType = typeof(decimal);
            ReferanceRangeDGV.Columns[6].ValueType = typeof(string);
            ReferanceRangeDGV.Columns[7].ValueType = typeof(decimal);
            ReferanceRangeDGV.Columns[8].ValueType = typeof(decimal);
            ReferanceRangeDGV.Columns[9].ValueType = typeof(string);
        }

        private void ReferanceRangeDGV_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (ReferanceRangeDGV.CurrentCell.Value == null)
            {
                MessageBox.Show("Cell Null");
            }

        
            //foreach (DataGridViewRow row in ReferanceRangeDGV.Rows)
            //{
            //    foreach (DataGridViewCell cell in row.Cells)
            //    {
            //        if (cell.Value == null)
            //        {
            //            MessageBox.Show("Cell Null");
            //        }
            //        else
            //        {
            //            MessageBox.Show("Cell Not Null");
            //        }
            //    }
            //}
        }

        private void ReferanceRangeDGV_RowLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (ReferanceRangeDGV.Rows[e.RowIndex].Cells[0].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[1].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[2].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[3].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[4].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[5].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[6].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[7].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[8].Value.ToString() == null
             || ReferanceRangeDGV.Rows[e.RowIndex].Cells[9].Value.ToString() == null)
            {
                MessageBox.Show("empty fields");
            }
            if ((ReferanceRangeDGV.Rows[e.RowIndex].Cells[7].Value.ToString() != null
              || ReferanceRangeDGV.Rows[e.RowIndex].Cells[8].Value.ToString() != null)&& ReferanceRangeDGV.Rows[e.RowIndex].Cells[9].Value.ToString() != null)
            {
                MessageBox.Show("duplicate reference");

            }

        }
    }
}

this is my form


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>