Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET CF set 'DroppedDown' for combobox

I want to open a combobox from my program on a mobile program (.net cf 3.5).

but there doesn't exist a property like cmbBox.DroppedDown in compact-framework Accesing WinCE ComboBox DroppedDown property (.NET CF 2.0) But I don't want to get the current state, but to set it.

How do I perform this?

like image 790
abc Avatar asked Dec 20 '22 08:12

abc


2 Answers

Use CB_SHOWDROPDOWN = 0x014F message:

    public const int CB_GETDROPPEDSTATE = 0x0157;
    public static bool GetDroppedDown(ComboBox comboBox)
    {
        Message comboBoxDroppedMsg = Message.Create(comboBox.Handle, CB_GETDROPPEDSTATE, IntPtr.Zero, IntPtr.Zero);
        MessageWindow.SendMessage(ref comboBoxDroppedMsg);
        return comboBoxDroppedMsg.Result != IntPtr.Zero;
    }

    public const int CB_SHOWDROPDOWN = 0x014F;
    public static bool ToogleDropDown(ComboBox comboBox)
    {
        int expand = GetDroppedDown(comboBox) ? 0 : 1;
        int size = Marshal.SizeOf(new Int32());
        IntPtr pBool = Marshal.AllocHGlobal(size);
        Marshal.WriteInt32(pBool, 0, expand);  // last parameter 0 (FALSE), 1 (TRUE)
        Message comboBoxDroppedMsg = Message.Create(comboBox.Handle, CB_SHOWDROPDOWN, pBool, IntPtr.Zero);
        MessageWindow.SendMessage(ref comboBoxDroppedMsg);
        Marshal.FreeHGlobal(pBool);
        return comboBoxDroppedMsg.Result != IntPtr.Zero;
    }
like image 166
StaWho Avatar answered Dec 28 '22 06:12

StaWho


You can take the same approach as in the referenced article and send it a Message.

Instead use const int CB_SHOWDROPDOWN = 0x14F for your message.

From that reference sample, modified a bit:

Message.Create(comboBox.Handle, CB_SHOWDROPDOWN , (IntPtr)1, IntPtr.Zero); // to open

Message.Create(comboBox.Handle, CB_SHOWDROPDOWN , (IntPtr)0, IntPtr.Zero); // to close
like image 32
tcarvin Avatar answered Dec 28 '22 05:12

tcarvin