You are creating a Windows Forms application by using the .NET Framework 3.5.
You plan to modify a list of orders within a DataGridView control in the application.
You need to ensure that a value is required in the first column of the grid control.
Which code segment should you use?
A.
private void dataGridOrders_CellValidated( object sender, DataGridViewCellEventArgs e) {
if (e.ColumnIndex == 0) { var cellValue = dataGridOrders[ e.ColumnIndex, e.RowIndex].Value;
if (cellValue == null || string.IsNullOrEmpty(cellValue.ToString())) {
dataGridOrders.EndEdit(); } } }
B.
private void dataGridOrders_Validated( object sender, EventArgs e) { if (dataGridOrders.CurrentCell.ColumnIndex == 0) {
var cellValue = dataGridOrders.Text;
if (cellValue == null || string.IsNullOrEmpty(cellValue.ToString())) {
dataGridOrders.EndEdit(); } }}
C.
private void dataGridOrders_Validating( object sender, CancelEventArgs e) { if (dataGridOrders.CurrentCell.ColumnIndex == 0) {
var cellValue = dataGridOrders.Text;
if (cellValue == null || string.IsNullOrEmpty(cellValue.ToString())) {
e.Cancel = true; } }}
D.
private void dataGridOrders_CellValidating( object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex == 0) {
if (e.FormattedValue == null || string.IsNullOrEmpty(e.FormattedValue.ToString())) {
e.Cancel = true; } }}