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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

masterpassCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.