Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a combobox, textbox, numericUpDown and a masktextbox. I want all these to be filled so that a
Posted
Updated 5-May-11 13:17pm
v5

It's because the Text property includes the "masked out" characters that the user is expected to fill in.
Try the MaskedTextBox.MaskCompleted[^] property instead.


"i did mtxtime.maskcompleted = false and it works
but the problem, i have a combobox where a specific item is selected, the masktextbox should be disabled automatically. however, when im doing what you told me, it is not letting me save now as it is recognising that the masttextbox is blank even disabled.
Enter your reply below and click the Submit button."



Yes, MaskCompleted is a bool, so you have to check it as such.
If you have disabled it, then you need to add the check for that into your expression.

If cboselect.SelectedIndex = -1 Or nuddigits.Value = 0 Or String.IsNullOrEmpty(textbox1.Text) Or Not mxttime.Enabled Or Not mxTtime.MaskCompleted Then



"No its the same. Ok, I will explain well.
I have a combobox which has 3 items namely Red, Blue, Black and Green. When Red or Blue is selected, the maskedtextbox is disabled else it is enabled for the other colours if selected.
when I select Red or Blue, the maskedtextbox is disabled, good, but the problem is I still can't save as even disabled when selected these colours, i get the message box to prompt me to fill it."



So? That's just a case of getting the logic right in your if condition:
If cboselect.SelectedIndex = -1
   Or nuddigits.Value = 0
   Or String.IsNullOrEmpty(textbox1.Text)
   Or (mxttime.Enabled And Not mxTtime.MaskCompleted)
Then
(I broke the lines up so you can see them a bit more easily)
 
Share this answer
 
v3
Comments
555336 4-Apr-11 10:11am    
i did mtxttime.maskcompleted = ""

is it good?
555336 4-Apr-11 10:16am    
i did mtxtime.maskcompleted = false and it works

but the problem, i have a combobox where a specific item is selected, the masktextbox should be disabled automatically. however, when im doing what you told me, it is not letting me save now as it is recognising that the masttextbox is blank even disabled.
OriginalGriff 4-Apr-11 11:20am    
Answer updated
555336 4-Apr-11 11:41am    
No its the same. Ok, I will explain well.

I have a combobox which has 3 items namely Red, Blue, Black and Green. When Red or Blue is selected, the maskedtextbox is disabled else it is enabled for the other colours if selected.

when I select Red or Blue, the maskedtextbox is disabled, good, but the problem is I still can't save as even disabled when selected these colours, i get the message box to prompt me to fill it.
OriginalGriff 4-Apr-11 11:54am    
Answer updated
Perhaps it has a space in it? You could try textbox1.Text.Trim = "" and see if that works.

If it doesn't work, try debugging and taking a look at what value IS actually in each textbox. You should be able to figure out a solution from there.
 
Share this answer
 
v2
Comments
OriginalGriff 4-Apr-11 11:23am    
When you use a MaskedTextBox, the Text property is almost never empty: the underlined spaces for the user to enter information are still there, as are any other characters used to guide the user as to what to enter: date separators for example. Better to check the MaskCompleted property instead.
Kschuler 4-Apr-11 11:25am    
Good to know. Thanks for the info. :)

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