I handle the validation in the Cell Validating event, and if the cell is invalid display an error message, then cancel the exit of edit mode.However I would also like to erase the content of the cell currently in edit mode. Space Then flag = True End If End Sub Private Sub Text Box_Key Press(By Val sender As System. Description: In Web Application Validation is little bit easy,but in Windows Application it is little bit Difficult to validate the Controls,here i am giving the Very Nice Code to Validate the Data Grid View Cells.i am Implemented Same code in My Project for Validating Cells. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.
The answer given is excellent unless you require decimal places as others have pointed out.
Add("Type C") '---create a combobox column--- Dim combo Box Col As New Data Grid View Combo Box Column '---set the header--- combo Box Col.
Header Text = "Types" '---add items to it--- combo Box Col.
Can you please explain your exact structure, why are you adding the Key Press event as you are doing it, inside the Data Grid View (in principle, not making too much sense)? Are you aware that the Text Box_key Press method you refer is attached to the Key Press event of the Text Box wrongly and thus this function will never be called (not when pressing a key in the Text Box)? unless, it has included a textbox in the Data Grid View (why?
Value 'null reference error here End Sub It is unclear what you are doing with the text Box/Data Grid View. But will test it (now with more information) and will correct my statement if required, but I was very calmed anyway. Never have seem such a thing (and not sure about the exact point). Private Sub Text Box_key Press(By Val sender As Object, By Val e As Key Press Event Args) If Char. Text 'Do stuff End If End Sub Why are you suggesting something without even understanding what the OP wants/what is going on?
The problem is: after one or two clicks, all cells get black background when focused. I guess event Microsoft doesn't know what is happening inside.