I have a windows form application which contains a datgridview.I need to enforce cell validations on the datagridview cells so that it does not accept negative values.So rather than doing foreach for row / cell you may want to get exact data for cell by using e. Column Index to extract cell data object from your data source. Doing so can cause your application or the operating system to stop responding.In this example, Employee ID is entered in the first column, and each ID must be unique.If you want to prevent duplicates based on entries in multiple columns, see the instructions below If you're not using an Excel table, as shown above, you can prevent duplicate entries in a specific range on the worksheet.But this is not working, what should be the type for a number column? First this depends on a datatype in your source collection. Best if you put conditional a breakpoint in this method for certain cell (column).FYI, this is an win Form application and different data is loaded in the datagridview on runtime by user choice. Also I would avoid iterating thru each row anc column because this method is called for specific cell.
The columns are Main Product (A), Sub Product (B), and Prod Code (C).Since i have a column name as "Item Name" which is supposed to be entered as text there is an issue in the code.It generates an error message when i type in the name of the item.For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section, and the "Message Deadlocks" section of the "About Messages and Message Queues" topic in the MSDN library at The following code example uses the derived class Text Box and validates an e-mail address that the user enters.