Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Well I have a combobox with 3 items namely: Product Size and Cost.
I have also a maskedtextbox.
Posted
Updated 11-Apr-11 8:43am
v2

1 solution

Hello again!

Since you have raised this as a new question, I will reply here, rather than to your message(s).

You already know how to enable and disable the MaskedTextBox: set the MaskedTextBox.Enabled property to true or false.

Does your combo box contain combinations of Product, Size, and Cost?
I.e. do you have all the permutations in the Items the user can select?
Product
Size
Cost
Product and Size
Product and Cost
Size and Cost
Product, Size and Cost
If so, then probably the best way is via a Select statement:
VB
Select Case cbOperation.SelectedText
    Case "Product", "Size", "Cost", "Product and Cost", "Size and Cost"
        tbCost.Enabled = False
        Exit Select
    Case "Product and Size", "Product, Size and Cost"
        tbCost.Enabled = True
        Exit Select
End Select

If not, then the user can't select a combination anyway... :laugh:

"Does not work dear, my codes below:

VB
Private Sub cboType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboType.SelectedIndexChanged

Select Case cboType.SelectedText
            Case "Product", "Size"
         mtxtCategory.Enabled = False
                Exit Select

 Case "Cost"
         mtxtCategory.Enabled = True
                Exit Select
        End Select



After reading your code, (and trying it so I realize you need a cast), try this:

VB
Select Case DirectCast(cbOperation.SelectedItem, String)
    Case "Cost", "Product and Cost", "Size and Cost", Else
        tbCost.Enabled = True
        Exit Select
    Case "Product", "Size", "Product and Size", "Product, Size and Cost"
        tbCost.Enabled = False
        Exit Select
End Select


You do realise that if your combo box only has the three items "Cost", "Product" and "Size" you cannot select a combination of "Product and Size", or "Product and Cost", don't you?

BTW: In western society, use of "dear" as an honorific (as in "Does not work dear,") is discouraged as it has sexist overtones. In this case I am male and take no offence, but you should be careful!
 
Share this answer
 
v2
Comments
555336 21-Mar-11 4:53am    
Does not work dear, my codes below:


End Select
555336 21-Mar-11 5:02am    
Hey friend, I did it, yes, I managed and finally got the good code by playing on the event. Look what I put:

End Select
OriginalGriff 21-Mar-11 5:18am    
Well done!
555336 21-Mar-11 5:53am    
:) By the way, do you know how to create a search box in Visual Basic? I want the search box based on streamreader. In proper terms, when I will input a text, it has to read on a text file in drice C. I know the streamreader code but don't know the code to do a search.

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