We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to prevent Null Col Values

Hello How can i make a cell in a grid control mandatory Field.i.e allow no null in the col . The grid is linked to a datatable.. I can set the col property AllowDBNull to false.. Can''t i similarly set the porperty of the grid col

3 Replies

AD Administrator Syncfusion Team September 24, 2004 09:41 PM UTC

If you set the DataColumn.AllowDbNull = false, then the grid should throw an exception each time your user tries to clear the cell. This should work witout ddition work if teh cell is a type like DataTime or double or anything other than a string. If this is a cell that has a string CellValue, then you may not want to allow the empty string as well. An empty string will not trigger the DBNull exception as an empty string is not null. To do this check take an extra step. You can handle the CurrentCellValidating event, and if grid.CurrentCell.Renderer.ControlText.Length == 0, then set e.Cancel = 0, and also set grid.CurrentCell.ErrorMessage if you want to see a message displayed.


GA Gaja September 26, 2004 10:52 PM UTC

Thanks for the reply .. i did set the Property of the datatable to AllowDBNull to false .. but now how to do i override this(Message.bmp attached) default error message .. I get this message when i try to go to a new row before filling in the no null column values ...Thanks a lot again in advance >If you set the DataColumn.AllowDbNull = false, then the grid should throw an exception each time your user tries to clear the cell. This should work witout ddition work if teh cell is a type like DataTime or double or anything other than a string. > >If this is a cell that has a string CellValue, then you may not want to allow the empty string as well. An empty string will not trigger the DBNull exception as an empty string is not null. To do this check take an extra step. You can handle the CurrentCellValidating event, and if grid.CurrentCell.Renderer.ControlText.Length == 0, then set e.Cancel = 0, and also set grid.CurrentCell.ErrorMessage if you want to see a message displayed. Message_1268.zip


AD Administrator Syncfusion Team September 26, 2004 10:57 PM UTC

You can handle the grid.ValidateFailed event. In the handler, you can set the message with code like: grid.CurrentCell.ErrorMessage = "My Message";

Loader.
Up arrow icon