locking of combo box

Dear All,

I just added a combo box in my form. I wrote the code in

public frmForm1()

//==================

{

//This call is required by the Windows Form Designer.

InitializeComponent();

comoboBox1.Items.Clear();

comoboBox1.Items.Add("USA");

comoboBox1.Items.Add("INDIA");

comoboBox1.Items.Add("UK");

comoboBox1.SelectedIndex = 0;

}

than i called the load event.

I would like to lock the combo box so that the user can see all the three values in combo box but will not be able to select the other items. In VB6 we generally locked the item and it solved the problem. But here I am facing a lots of problem for this in Visual Studio 2005. Can you tell me please How can I resolve the problem.

Regards,

Biswajit



Answer this question

locking of combo box

  • CESAR DE LA TORRE

    ComboBox1.Enabled = false;
  • Andrew Todd

    No its not a web app that I am creating. I just set the combo box drop down property to DropDownList. The values are displaying right. But the problem remains same. I would like to lock the combo box so that the user can see all the items in the combo box but would not be able to select any items from there.


  • Dick Campbell

    No abcdefgqwerty2 ,

    just not allowing the user to select any of the available items ,even though they can be seen.

    Ofcourse , we can do one more thing like not even display all  the unnecessary items by setting the 'MaxDropDownItems' property value to 1.

    I don't know what 'Biswajit' comments on this.

     

    Regards,

    Ch.T.Gopi Kumar.



  • Cla82

    Dear Gavin,

    In my combo box I have 5 items i.e. "Rice", "Wheat", "Paper", "Surf" and "Coke".

    From that User can see all items. But will be able to select only two items. i.e. Rice and Coke and the other item can be seen but user will not be able to select it.

    How can I resolve this problem

    Regards,

    Biswajit


  • dwrayment

    Could  you show some code,nomally,it will not happen things like that.



  • KompjoeFriek

    I think you can do in this way:

    1.populate DropDownStyle=Simple

    2.Enabled=false

    3. Me.ComboBox1.SelectedIndex = 3

    I hope it helps :)



  • sajohnstone

    I think you want to change the dropdownstyle to DropDownList (Winforms)

    If it's a web app I think there is two types of drop down and you have to select the correct one.


  • ProSlamBanO

    Hi Biswajit,

        Finally which implementation u've followed or u'll be following I want to know the best approach for ur requirement.

     

    Thanx,

    Ch.T.Gopi Kumar.

      



  • Aquineas

    Hi. Just subscribe to the combobox SelectedIndexChanged event (select the combobox on the form, go to properties, switch to the event view there and double click the "SelectedIndexChanged" entry. It's the same as if you add the click event handler to a button) and set the selected index back:

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    {

    comboBox1.SelectedIndex = -1;

    }



  • Tkanos

    Hi,

    I guess, the definition of the function 'comboBox1_SelectedIndexChanged' like as follows..

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    {

    comboBox1.SelectedIndex = 0; // I suppose it's not -1 , since every time oly the first item has to be shown- as per the requirement.

    }

    Hope i'm not wrong.

    Thanx,

    Ch.T.Gopi Kumar.



  • Menachem_P

    like disabling the control maybe i dont understand.

  • Paul Diston

    I see so you want the combo box to be permanently on show so you are effectively showing a list to the user

    If this is what you want it sounds more like you want the ListBox control

    If you want a drop down that contains entries but are not selectable i'm not sure right now how to achieve that.


  • barryt.net

    Cminor wrote:
    ComboBox1.Enabled = false;

    This is the solution - simply disabling it will allow view (but not scrolling so if you have more than three items this may not work)

    If you need to allow scrolling then I suggest you set the background colour to the disabled grey colour, then on the onItemSelect or whatever the event is called set the selected index=-1

    Hope this helps

    Ross



  • GS80

    If a combobox is disabled you can see all the items but they cant be selected right

  • locking of combo box