Set datagridview cell mandatory.

Hi everyone,

I tried to Google the web for quite sometime now but I can't seem to find the solution to the problem I am facing.

I have a typical datagridview, not the web one where I have 5 rows to begin with, any any given time if any column is populated or filled out with a value, the rest of the cells in that row become mandatory fields.  Opposite to text box where you can set the MandatoryField, I can't find a way to set the currentcell or the datagridview[column,cell] or find any of their related attributes to set that specific cell to mandatory.

From reading what I described so far you can see this attribute has to be dynamic, that is if the user decide to blank out all values within a row then all the cell in that row will change from mandatory back to non mandatory.

Any tips or resources on this are greatly appreciated.
fylix0000Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
masterpassConnect With a Mentor Commented:
you will have to write the code in cellvalidating event and dynamically set the values

have a look here

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_24860344.html
0
 
Dhanasekaran SengodanCommented:

Hi,

Here's the sample on msdn: (http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvalidating.aspx)

private void dataGridView1_CellValidating(object sender,
  DataGridViewCellValidatingEventArgs e)
{
  dataGridView1.Rows[e.RowIndex].ErrorText = "";
  int newInteger;

  // Don't try to validate the 'new row' until finished
  // editing since there
  // is not any point in validating its initial value.
  if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; }
  if (!int.TryParse(e.FormattedValue.ToString(),
    out newInteger) || newInteger < 0)
  {
    e.Cancel = true;
    dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer";
  }
}

Maybe the behavior you see is because you are validating a new row

http://www.codeguru.com/forum/showthread.php?t=416029
0
All Courses

From novice to tech pro — start learning today.