Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello Experts,

I have a Textbox, Checked listbox and Combo box in my windows form. Now I have to make my program in such a sway that, any one of these three should be entered. For example, If I enter Textbox, I have to check if Combo box and Checked Listbox are not selected. Only then I have to run my function.
Here is what I tried

SQL
If txtAccount.Text.ToString().Length() > 0 Then
      If cmbProgram.SelectedItem.ToString().Length = 0 Or   chkClasslist.SelectedItem.ToString().Length = 0 Then
        Panel2.Visible = True

End If



And I get Object reference not set to instance...

Could someone help me to achieve my req.?
Posted
Updated 15-Apr-15 3:34am
v2

Hi,



Use "String.IsNullOrEmpty()" instead of ToString().Length = 0


If Not String.IsNullOrEmpty(txtAccount.Text) Then
If String.IsNullOrEmpty(cmbProgram.Text) Or String.IsNullOrEmpty(Convert.ToString(cmbProgram.SelectedItem)) Or String.IsNullOrEmpty(chkClasslist.Text) Or String.IsNullOrEmpty(Convert.ToString(chkClasslist.SelectedItem)) Then
Panel2.Visible = True
End If
End If

Thanks
 
Share this answer
 
v2
Try this!


If (txtAccount.Text <> String.Empty AndAlso cmbProgram.SelectedItem is Nothing AndAlso chkClasslist.SelectedItem is Nothing) orelse

(txtAccount.Text = String.Empty AndAlso cmbProgram.SelectedItem isNot Nothing AndAlso chkClasslist.SelectedItem is Nothing)

orelse

(txtAccount.Text = String.Empty AndAlso cmbProgram.SelectedItem is Nothing AndAlso chkClasslist.SelectedItem isNot Nothing)

Then
Panel2.Visible = True

End If
 
Share this answer
 
v3
Comments
sudevsu 15-Apr-15 9:56am    
Thanks. Didn't help though
Anil_Kumar_India 15-Apr-15 10:15am    
Another option is to attach a observer function to onChange/OnSelectedIndexChange. This observer will tell no of controls selected in this case your condition will be like
If (observer.ControlsNo=1) Then
---
Anil_Kumar_India 15-Apr-15 9:57am    
Got it now, you actually want to make the Panel visible when only one has value, please check updated answer.

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