Glide List, Dropdown.Options causes an exception

I am trying to implement a Dropdown (i.e. ComboBox) in Glide, but instead of supplying an XML file, I am handcrafting the objects on the page.

I am getting an exception when I pass try and instantiate the ‘list’

Hardcoded way of adding dropdown list items…


<Glide Version="x.x.x">
  <Window Name="window" Width="320" Height="240" BackColor="dce3e7">
    <Dropdown Name="dropdown" X="100" Y="104" Width="120" Height="32" Alpha="255" Text="Select:" Font="4" FontColor="000000">
      <Option Value="Data0">Label0</Option>
      <Option Value="Data1">Label1</Option>
      <Option Value="Data2">Label2</Option>
      <Option Value="Data3">Label3</Option>
      <Option Value="Data4">Label4</Option>
      <Option Value="Data5">Label5</Option>
      <Option Value="Data6">Label6</Option>
      <Option Value="Data7">Label7</Option>
      <Option Value="Data8">Label8</Option>
      <Option Value="Data9">Label9</Option>
    </Dropdown>
  </Window>
</Glide>

GHI Library example code using XML


using System.Threading;

using Microsoft.SPOT;

using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;

namespace Test
{
    public class Program
    {
        // This will hold the main window.
        static Window window;

        // This will hold our dropdown's list.
        static List list = null;

        public static void Main()
        {
            // Load the window
            window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Window));

            // Activate touch
            GlideTouch.Initialize();

            // Initialize the window.
            InitWin();

            // Assigning a window to MainWindow flushes it to the screen.
            // This also starts event handling on the window.
            Glide.MainWindow = window;

            Thread.Sleep(-1);
        }

        static void InitWin()
        {
            // Get the Dropdown
            Dropdown dropdown = (Dropdown)window.GetChildByName("dropdown");
            dropdown.TapEvent += new OnTap(dropdown_TapEvent);
            dropdown.ValueChangedEvent += new OnValueChanged(dropdown_ValueChangedEvent);

            // Create the list that the Dropdown uses...
            list = new List(dropdown.Options, 150);
            list.CloseEvent += new OnClose(list_CloseEvent);
        }

        // When the Dropdown is tapped it will open it's list.
        static void dropdown_TapEvent(object sender)
        {
            Glide.OpenList(sender, list);
        }

        // This shows when the Dropdown's value changes.
        static void dropdown_ValueChangedEvent(object sender)
        {
            Dropdown dropdown = (Dropdown)sender;
            Debug.Print("Dropdown value: " + dropdown.Text + " : " + dropdown.Value.ToString());
        }

        static void list_CloseEvent(object sender)
        {
            Glide.CloseList();
        }
    }
}

My handcrafted variant on the above example - that is generating an exception


ListOptions mListOptions;
Dropdown mDropdown;
.....
            int x = 10;
            int w = 250; //must be > 100 and lesst than LCD width
            int h = 30;
            int y =  10;

            mListOptions = new ArrayList();

            mDropdown = new Dropdown("dropdown_list",255, x, y, w, h);
            for (int k = 0; k < 5; k++)
            {
                    ListItem a = new ListItem("Label"+k.ToString(), "myVal"+k.ToString());
                    mDropdown.Options.Add(a);
            }
            mDropdown.TapEvent += new OnTap(Dropdown_TapEvent);
            mDropdown.ValueChangedEvent += new OnValueChanged(Dropdown_ValueChangedEvent);
            mDropdown.Text = "Select...";
            mList = new List(mDropdown.Options, 150);    // <<<<<<<<<<<<<<<<<<<<<<Exception Here
            mList.CloseEvent += new OnClose(List_CloseEvent);

My Exception is:
An unhandled exception of type ‘System.InvalidCastException’ occurred in GHIElectronics.NETMF.Glide.dll

The mDropdown.Options is populated with 5 items and teh label and value are alos populated.

Any ideas?

In Addition:

BTW I can get the XML version working,

BUT l can only see/access 7 of the 10 items on the LCD screen, and there is no scroll enabled to access the other items? How would I also solve access to data 7 - Data9?

I have also tries to switch Label0 with Data0, in my hand crafted example with no change .

That is also my problem now Earthed. Have you solve it? if yes, how?
Thank you.

Try placing your finger on the list and dragging the items up and down like you would a phone.

i had the same issue. i decided to look into the source code of glide, and found that it takes a 2 object array to enter objects (also found on the examples page for glide.

this:

ListItem a = new ListItem("Label"+k.ToString(), "myVal"+k.ToString());
 mDropdown.Options.Add(a);

should be:

 object[] a = new object[] {"Label" + k.ToString(), "myVal" + k.ToString()};
mDropdown.Options.Add(a);