Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am designing a Windows Form where i need to make some textbox a required field. I am doing the validation . But just curious if i can display the symbol * (red) in the form itself. Is there a way to do like this in Windows Form. Please help

FirstName *(red) TextBox Control
Posted
Comments
Simon_Whale 30-Jul-13 11:23am    
Are you validating these value before they go into a database?
vidkaat 30-Jul-13 11:33am    
Yes ...
Simon_Whale 30-Jul-13 11:48am    
Solutions will depend on how you are connecting to the database are you using Entity Framework, ADO.NET with dataset's and datatables?

1 solution

Put a Label Control next to the TextBox Control.
Put an * in the Label Control.
Size the Label Control to the size of the *.
Change the ForeColor attribute of the Label Control to red.
 
Share this answer
 
Comments
vidkaat 30-Jul-13 11:28am    
Easy way :-)..Is there any other way?
Mike Meinz 30-Jul-13 11:57am    
That's the way to do it.
Dave Kreskowiak 30-Jul-13 12:46pm    
That's the easy way to do it, but it's not exactly "reusable" for say, 20 textboxes on the form.

I made a custom validation control suite that you can drag and drop on the form, then just tell it which textbox should be required. The control(s) handles the rest, like putting up the red exclamation mark and whatnot. I've got a few validators made up, like RequiredFieldValidator and RegExValidator. It's exandable so you can create any number of different validators you want.

Sorry, I don't have time to write up an article on it! ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900