i make a form to record a values but i need
- control on a cell to check a datatype and if empty
- control a record if some cells empty
- 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