Change combobox value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rickard Hill
    New Member
    • Sep 2010
    • 3

    Change combobox value

    Fellow csharpers..

    I got a problem that I haven't found a solution for, and are hoping to get some help.

    I have the following piece of code (with commented out parts that I tried without success)
    Hoping someone can help me.

    Code:
    else if (msg[0].ToString() == "set")
                        {
                            MessageBox.Show(msg[0].ToString());
                            if (msg[1].ToString() == "master")
                            {
                                MessageBox.Show(msg[1].ToString());
                                int num;
                                if (Int32.TryParse(msg[2], out num))
                                {
                                    int NMasters = MasterBox.Items.Count;
                                    MessageBox.Show(NMasters.ToString());
                                    if (num < 1)
                                    {
                                        Client.Self.InstantMessage(e.IM.FromAgentID, "[ERROR]: Invalid number (lower than NMasters), please try again!");
                                    }
                                    else if (num > NMasters)
                                    {
                                        Client.Self.InstantMessage(e.IM.FromAgentID, "[ERROR]: Invalid number (Higher than NMasters), please try again!");
                                    }
                                    else
                                    {
                                        MessageBox.Show("MEH");
                                        MasterBox.Select(num, num);
                                        //MasterBox.DroppedDown = true;
                                        //MasterBox.SelectedItem = num;
                                        //MasterBox.DroppedDown = false;
                                        //MasterName = MasterBox.SelectedItem.ToString();
                                        //GetMKey();
                                    }
                                }
                            }
                        }
    Everything is working, up until where I want the combobox (MasterBox) to change.
    The command "set master X" is supposed to change the selected item inside the combobox, but whatever I try won't work.

    Is it possible at all to do it the way I am trying to? Or do I have to re-think it all?

    I am not too good (yet) with Csharp, so hopefully someone can point me in the right direction.

    Thank you all!
  • marcellus7
    New Member
    • Oct 2008
    • 33

    #2
    Im not sure I exactly get what you're trying to do, but how about:

    Code:
    MasterBox.SelectedIndex = num - 1

    Comment

    Working...