Click here to Skip to main content
15,886,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My problem is
i have one combobox1 control and inside the five items into the combobox control.
i want when i selec titem1 inside the combobox1 control so other combobox2 should be visible. same as when i select item2 then combobox2 should be visible and combobox1 should be invisible.
i have tried and my codes are below but problem is only first item does visible only and other does
not please guide me


private void courtnamelist_SelectedIndexChanged(object sender, EventArgs e)
      {

           districtcourtlist.Visible = false;
           supremecourtlist.Visible = false;
           heighcourtlist.Visible = false;
           nationlgreentribunallict.Visible = false;
           labourcourtlist.Visible = false;


         int[] arr = new int[10];
         int selectinsexval = courtnamelist.SelectedIndex;

         if (selectinsexval == arr[0])
         {
             supremecourtlist.Visible = true;
             districtcourtlist.Visible = false;

             heighcourtlist.Visible = false;
             nationlgreentribunallict.Visible = false;
             labourcourtlist.Visible = false;

         }
         else if (selectinsexval == arr[1])
         {
             heighcourtlist.Visible = true;
             supremecourtlist.Visible = true;
             districtcourtlist.Visible = false;


             nationlgreentribunallict.Visible = false;
             labourcourtlist.Visible = false;
          }
         else if (selectinsexval == arr[2])
         {
             heighcourtlist.Visible = true;
             supremecourtlist.Visible = true;
             districtcourtlist.Visible = false;


             nationlgreentribunallict.Visible = false;
             labourcourtlist.Visible = false;
         }


     }
Posted

1 solution

You compare your 'selectinsexval' with the contents of a not assigned (new) Integer-Array.
Inside this Array, all elements which are not assigned are ==0.
If you select your first Item inside your Combobox it has the Index==0. So it works.
The next Item has Index==1 ...

Did you get what I mean ...?
Perhaps comparewith constants ...
 
Share this answer
 
v2
Comments
faizyab 2009 8-Jun-15 1:39am    
nope!! i did not get it. please correct my codes. where io am wrong. i tried it from switch case but it does not work .i will be grateful to you sir
faizyab 2009 8-Jun-15 1:56am    
Sir i tried as you are saying to me. i hope it will work if i will assign arr[0]=Comboxbox1.SelectedIndex,arr[1]=Comboxbox2.SelectedIndex,arr[2]=Comboxbox3.SelectedIndex
Did it your mean ????
Vipin Patil 8-Jun-15 2:00am    
your arr variable is not assign with any value it is empty array
and you are checking selectinsexval value to arr's value
Vipin Patil 8-Jun-15 2:04am    
no you can directly check selected index with int values like
if(selectinsexval == 1){}
else if(selectinsexval == 2){}

or
Switch(selectinsexval)
{
case 1:your code; break
case 2:your code; break
}
faizyab 2009 8-Jun-15 2:24am    
now have donle like this way plz check

private void courtnamelist_SelectedIndexChanged(object sender, EventArgs e)
{

int[] arr=new int[5];
arr[0] = supremecourtlist.SelectedIndex;
arr[1] = districtcourtlist.SelectedIndex;
arr[2] = heighcourtlist.SelectedIndex;
arr[3] = nationlgreentribunallict.SelectedIndex;


int selectinsexval = courtnamelist.SelectedIndex;

if (arr[0]==selectinsexval)
{
supremecourtlist.Visible = true;
button8.Visible = false;
}
else if (arr[1] == selectinsexval)
{

districtcourtlist.Visible = true;


}
else if (arr[2] == selectinsexval)
{
heighcourtlist.Visible = true;


}


}

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