Get the list from from iexplorer combo box

Discussion in 'ASP .Net Web Controls' started by ME, Apr 10, 2006.

  1. ME

    ME Guest

    I need to be able to get the list from a combobox using PInvoke. This code
    works fine for a windows form application however I need to read the
    combobox that is on an HTML page (inside iexplorer, the class name for the
    box is "Internet Explorer_TridentCmboBx" ). When I read the combobox from
    IE it will accurately get the count, but the text of each item returns non
    printable ascii characters.

    What am I doing wrong?

    Thanks,

    Matt

    //C#


    //------------------------------ CODE ---------------------

    public const UInt32 CB_GETCOUNT = 0x0146;
    public const UInt32 CB_GETCURSEL = 0x0147;
    public const UInt32 CB_GETLBTEXT = 0x0148;
    public const UInt32 CB_GETLBTEXTLEN = 0x0149;

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam,
    IntPtr lParam);
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam,
    StringBuilder lParam);

    public static List<ListItemVals> GetListItems(IntPtr controlPointer, object
    sender)
    {
    int count = 0;
    List<ListItemVals> retVal = new List<ListItemVals>();
    ListItemVals item = new ListItemVals();
    IntPtr zero = new IntPtr(0);
    //Get the count of items in the list
    IntPtr ptr = SendMessage(GetHandleRef(controlPointer, sender), CB_GETCOUNT,
    zero, zero);
    count = ptr.ToInt32();
    for (int i = 0; i < count; i++)
    {
    item = GetValueFromCombo(controlPointer, sender, i);
    retVal.Add(item);
    }
    return retVal;
    }
    public static ListItemVals GetValueFromCombo(IntPtr pointer, object sender,
    int index)
    {
    //List<ListItemVals> retVal = new List<ListItemVals>();
    int len = 0;
    StringBuilder sb = new StringBuilder();
    ListItemVals item = new ListItemVals();
    IntPtr wParam = new IntPtr(index);
    IntPtr zero = new IntPtr(0);
    //Get the count of items in the list
    IntPtr ptr = SendMessage(GetHandleRef(pointer, sender), CB_GETLBTEXTLEN ,
    wParam, zero);
    len = ptr.ToInt32();
    sb.Capacity = len;
    IntPtr txtPtr = SendMessage(GetHandleRef(pointer, sender), CB_GETLBTEXT,
    wParam, sb);
    //Get the list item
    item.textValue = sb.ToString();
    item.itemValue = wParam.ToInt32();

    //return the value
    return item;
    }
     
    ME, Apr 10, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5nZWw=?=

    COMBO BOX INSTEAD OF DROP DOWN BOX

    =?Utf-8?B?QW5nZWw=?=, Jun 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    653
    Ken Cox [Microsoft MVP]
    Jun 29, 2004
  2. Adrian
    Replies:
    1
    Views:
    250
    Bullschmidt
    Feb 18, 2004
  3. dthmtlgod

    Fill Combo Box based on another Combo Box

    dthmtlgod, Nov 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    624
    Bob Barrows [MVP]
    Nov 16, 2005
  4. Mike

    Combo Box and text box

    Mike, Sep 24, 2003, in forum: Javascript
    Replies:
    2
    Views:
    182
  5. SM
    Replies:
    2
    Views:
    403
Loading...

Share This Page