How to get ListItemValue and ListItemText from a Combo using SendMessage

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

  1. ME

    ME Guest

    I am new to interop services as well as the Windows API in general. What is
    the proper way to obtain the ListItemValue and the ListItemText using the
    windows API? I would like to be able to read a combo's list values from a
    windows form application (ComboBox) and also from a combo on a web page
    (Internet Explorer_TridentCmboBx). I can not seem to locate much
    documentation or even code examples. I am using C#.

    Thanks

    Matt
     
    ME, Apr 3, 2006
    #1
    1. Advertising

  2. Matt,

    What are these ListItemValue and ListItemText on the WindowsForms' combobox?


    --

    Stoitcho Goutsev (100)

    "ME" <> wrote in message
    news:...
    >I am new to interop services as well as the Windows API in general. What
    >is
    > the proper way to obtain the ListItemValue and the ListItemText using the
    > windows API? I would like to be able to read a combo's list values from a
    > windows form application (ComboBox) and also from a combo on a web page
    > (Internet Explorer_TridentCmboBx). I can not seem to locate much
    > documentation or even code examples. I am using C#.
    >
    > Thanks
    >
    > Matt
    >
    >
    >
     
    Stoitcho Goutsev \(100\), Apr 3, 2006
    #2
    1. Advertising

  3. ME

    ME Guest

    Please forgive my use of the wrong term. ValueMember and DisplayMember are
    used to BIND the values in .NET combobox on form, however in Visual Basic 6
    you had ItemData and List. In ASP.NET you have Text and Value properties of
    the Item object (DropDownList.Items[x]). The point is there are many ways
    to make a combo have two corresponding values, a display version (text) and
    an underlining programmatic version (value). I would like to know how to
    read both sets of data from a combo using the windows api.

    I have a web page which I need to generate a new UI for. Unfortunately the
    page can not be modified by me, the end user. The page contains combos (or
    dropdownlists) that have items in no logical order (over 100 items). I want
    to display a form to a user with the same list, just alphabetized. When a
    user selects the item in my list I want to programmatically select the item
    in the original mixxed up list. I want to make sure that if any value in
    the list has the same display TEXT, that I will be able to determine which
    one is which based on the other itemVALUE associated with it.

    The need for a windows forms version is because this also occurs a windows
    form appliction with a similar problem. The programmers were idiots and it
    will be at least a year before they even think about fixing thier list
    boxes. I want to write a app to work with both.

    Thanks,

    Matt

    "Stoitcho Goutsev (100)" <> wrote in message
    news:...
    > Matt,
    >
    > What are these ListItemValue and ListItemText on the WindowsForms'
    > combobox?
    >
    >
    > --
    >
    > Stoitcho Goutsev (100)
    >
    > "ME" <> wrote in message
    > news:...
    >>I am new to interop services as well as the Windows API in general. What
    >>is
    >> the proper way to obtain the ListItemValue and the ListItemText using the
    >> windows API? I would like to be able to read a combo's list values from
    >> a
    >> windows form application (ComboBox) and also from a combo on a web page
    >> (Internet Explorer_TridentCmboBx). I can not seem to locate much
    >> documentation or even code examples. I am using C#.
    >>
    >> Thanks
    >>
    >> Matt
    >>
    >>
    >>

    >
    >
     
    ME, Apr 3, 2006
    #3
  4. ME

    Weaver2112 Guest

    Hi,
    I should apologize, initially I thought list and treeviews were the
    same thing. I was mistaken. I am in fact dealing with a treeview.

    The TreeView consist of Check Boxes and Some descriptive text.
    I.E. I have a treeview (Systree32) which has 8 elements in it.
    Each element consist of an option which is installed based on whether
    or not the corresponding check box value. If the box is checked and you
    go to the next window then some action will take place- in this
    situation it is the installation of some software.
    I would like to run the software and check all of the boxes -emulating
    a user. I have figured out how to acces objects and get the window
    handles for them. I have figured out how to activate buttons and
    navigate menus. For some reason I am missing out on something in these
    list view and tree views.
    For example- One of the elements on the treeview is named GUMMT with a
    check box next to it.
    I know the acronym "GUMMT" will always be there next to the check box.
    I have the window handle to the treeview, but I don't know how to
    access and navigate through the elements of the tree view. Once I can
    do that I will want to figure out how to check the boxes.
    Any suggestions on how to do this or where I should go to learn? I was
    on MSDN but I did not see anything on accessing tree or list view
    children.
    I apologize for confusing the matter with listviews.
    If you can help it would be great.
    Thanks for reading my post. It is nice to know I am not alone.
    Matt




    Stoitcho Goutsev (100) wrote:
    > Matt,
    >
    > What are these ListItemValue and ListItemText on the WindowsForms' combobox?
    >
    >
    > --
    >
    > Stoitcho Goutsev (100)
    >
    > "ME" <> wrote in message
    > news:...
    > >I am new to interop services as well as the Windows API in general. What
    > >is
    > > the proper way to obtain the ListItemValue and the ListItemText using the
    > > windows API? I would like to be able to read a combo's list values from a
    > > windows form application (ComboBox) and also from a combo on a web page
    > > (Internet Explorer_TridentCmboBx). I can not seem to locate much
    > > documentation or even code examples. I am using C#.
    > >
    > > Thanks
    > >
    > > Matt
    > >
    > >
    > >
     
    Weaver2112, Apr 3, 2006
    #4
  5. Matt,

    You cannot read it from Windows native API. They don't exist there. Native
    windows combobox control has only one value and this is the text that you
    see. DisplayMember and ValueMember are part of the .NET control.


    --

    Stoitcho Goutsev (100)

    "ME" <> wrote in message
    news:...
    > Please forgive my use of the wrong term. ValueMember and DisplayMember
    > are used to BIND the values in .NET combobox on form, however in Visual
    > Basic 6 you had ItemData and List. In ASP.NET you have Text and Value
    > properties of the Item object (DropDownList.Items[x]). The point is there
    > are many ways to make a combo have two corresponding values, a display
    > version (text) and an underlining programmatic version (value). I would
    > like to know how to read both sets of data from a combo using the windows
    > api.
    >
    > I have a web page which I need to generate a new UI for. Unfortunately
    > the page can not be modified by me, the end user. The page contains
    > combos (or dropdownlists) that have items in no logical order (over 100
    > items). I want to display a form to a user with the same list, just
    > alphabetized. When a user selects the item in my list I want to
    > programmatically select the item in the original mixxed up list. I want
    > to make sure that if any value in the list has the same display TEXT, that
    > I will be able to determine which one is which based on the other
    > itemVALUE associated with it.
    >
    > The need for a windows forms version is because this also occurs a windows
    > form appliction with a similar problem. The programmers were idiots and
    > it will be at least a year before they even think about fixing thier list
    > boxes. I want to write a app to work with both.
    >
    > Thanks,
    >
    > Matt
    >
    > "Stoitcho Goutsev (100)" <> wrote in message
    > news:...
    >> Matt,
    >>
    >> What are these ListItemValue and ListItemText on the WindowsForms'
    >> combobox?
    >>
    >>
    >> --
    >>
    >> Stoitcho Goutsev (100)
    >>
    >> "ME" <> wrote in message
    >> news:...
    >>>I am new to interop services as well as the Windows API in general. What
    >>>is
    >>> the proper way to obtain the ListItemValue and the ListItemText using
    >>> the
    >>> windows API? I would like to be able to read a combo's list values from
    >>> a
    >>> windows form application (ComboBox) and also from a combo on a web page
    >>> (Internet Explorer_TridentCmboBx). I can not seem to locate much
    >>> documentation or even code examples. I am using C#.
    >>>
    >>> Thanks
    >>>
    >>> Matt
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Stoitcho Goutsev \(100\), Apr 4, 2006
    #5
  6. ME

    ME Guest

    Thanks for your input. What would the "CB_GETITEMDATA" message do then? It
    appears that the "CB_GETLBTEXT" message retrieves the text value of the
    item. I can not seem to find any examples of "CB_GETITEMDATA" being used.

    http://msdn.microsoft.com/library/d...reference/comboboxmessages/cb_getitemdata.asp

    Thanks,

    Matt


    "Stoitcho Goutsev (100)" <> wrote in message
    news:exzJFn%...
    > Matt,
    >
    > You cannot read it from Windows native API. They don't exist there. Native
    > windows combobox control has only one value and this is the text that you
    > see. DisplayMember and ValueMember are part of the .NET control.
    >
    >
    > --
    >
    > Stoitcho Goutsev (100)
    >
    > "ME" <> wrote in message
    > news:...
    >> Please forgive my use of the wrong term. ValueMember and DisplayMember
    >> are used to BIND the values in .NET combobox on form, however in Visual
    >> Basic 6 you had ItemData and List. In ASP.NET you have Text and Value
    >> properties of the Item object (DropDownList.Items[x]). The point is
    >> there are many ways to make a combo have two corresponding values, a
    >> display version (text) and an underlining programmatic version (value).
    >> I would like to know how to read both sets of data from a combo using the
    >> windows api.
    >>
    >> I have a web page which I need to generate a new UI for. Unfortunately
    >> the page can not be modified by me, the end user. The page contains
    >> combos (or dropdownlists) that have items in no logical order (over 100
    >> items). I want to display a form to a user with the same list, just
    >> alphabetized. When a user selects the item in my list I want to
    >> programmatically select the item in the original mixxed up list. I want
    >> to make sure that if any value in the list has the same display TEXT,
    >> that I will be able to determine which one is which based on the other
    >> itemVALUE associated with it.
    >>
    >> The need for a windows forms version is because this also occurs a
    >> windows form appliction with a similar problem. The programmers were
    >> idiots and it will be at least a year before they even think about fixing
    >> thier list boxes. I want to write a app to work with both.
    >>
    >> Thanks,
    >>
    >> Matt
    >>
    >> "Stoitcho Goutsev (100)" <> wrote in message
    >> news:...
    >>> Matt,
    >>>
    >>> What are these ListItemValue and ListItemText on the WindowsForms'
    >>> combobox?
    >>>
    >>>
    >>> --
    >>>
    >>> Stoitcho Goutsev (100)
    >>>
    >>> "ME" <> wrote in message
    >>> news:...
    >>>>I am new to interop services as well as the Windows API in general.
    >>>>What is
    >>>> the proper way to obtain the ListItemValue and the ListItemText using
    >>>> the
    >>>> windows API? I would like to be able to read a combo's list values
    >>>> from a
    >>>> windows form application (ComboBox) and also from a combo on a web page
    >>>> (Internet Explorer_TridentCmboBx). I can not seem to locate much
    >>>> documentation or even code examples. I am using C#.
    >>>>
    >>>> Thanks
    >>>>
    >>>> Matt
    >>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    ME, Apr 4, 2006
    #6
  7. Matt,

    you can attach a user data which is 32 bit number. What this number means is
    up to you. It could be a number or it could be a pointer to a bigger data
    structure. Ususally this is used in the case of owner-drawn comboboxes when
    the style CBS_HASSTRINGS is not set.


    I'm pretty sure WindowsForms uses that for keeping references with the
    items, but I doubt it has anything to do with the vlue and display members


    Stoitcho Goutsev (100)

    "ME" <> wrote in message
    news:...
    > Thanks for your input. What would the "CB_GETITEMDATA" message do then?
    > It appears that the "CB_GETLBTEXT" message retrieves the text value of the
    > item. I can not seem to find any examples of "CB_GETITEMDATA" being used.
    >
    > http://msdn.microsoft.com/library/d...reference/comboboxmessages/cb_getitemdata.asp
    >
    > Thanks,
    >
    > Matt
    >
    >
    > "Stoitcho Goutsev (100)" <> wrote in message
    > news:exzJFn%...
    >> Matt,
    >>
    >> You cannot read it from Windows native API. They don't exist there.
    >> Native windows combobox control has only one value and this is the text
    >> that you see. DisplayMember and ValueMember are part of the .NET control.
    >>
    >>
    >> --
    >>
    >> Stoitcho Goutsev (100)
    >>
    >> "ME" <> wrote in message
    >> news:...
    >>> Please forgive my use of the wrong term. ValueMember and DisplayMember
    >>> are used to BIND the values in .NET combobox on form, however in Visual
    >>> Basic 6 you had ItemData and List. In ASP.NET you have Text and Value
    >>> properties of the Item object (DropDownList.Items[x]). The point is
    >>> there are many ways to make a combo have two corresponding values, a
    >>> display version (text) and an underlining programmatic version (value).
    >>> I would like to know how to read both sets of data from a combo using
    >>> the windows api.
    >>>
    >>> I have a web page which I need to generate a new UI for. Unfortunately
    >>> the page can not be modified by me, the end user. The page contains
    >>> combos (or dropdownlists) that have items in no logical order (over 100
    >>> items). I want to display a form to a user with the same list, just
    >>> alphabetized. When a user selects the item in my list I want to
    >>> programmatically select the item in the original mixxed up list. I want
    >>> to make sure that if any value in the list has the same display TEXT,
    >>> that I will be able to determine which one is which based on the other
    >>> itemVALUE associated with it.
    >>>
    >>> The need for a windows forms version is because this also occurs a
    >>> windows form appliction with a similar problem. The programmers were
    >>> idiots and it will be at least a year before they even think about
    >>> fixing thier list boxes. I want to write a app to work with both.
    >>>
    >>> Thanks,
    >>>
    >>> Matt
    >>>
    >>> "Stoitcho Goutsev (100)" <> wrote in message
    >>> news:...
    >>>> Matt,
    >>>>
    >>>> What are these ListItemValue and ListItemText on the WindowsForms'
    >>>> combobox?
    >>>>
    >>>>
    >>>> --
    >>>>
    >>>> Stoitcho Goutsev (100)
    >>>>
    >>>> "ME" <> wrote in message
    >>>> news:...
    >>>>>I am new to interop services as well as the Windows API in general.
    >>>>>What is
    >>>>> the proper way to obtain the ListItemValue and the ListItemText using
    >>>>> the
    >>>>> windows API? I would like to be able to read a combo's list values
    >>>>> from a
    >>>>> windows form application (ComboBox) and also from a combo on a web
    >>>>> page
    >>>>> (Internet Explorer_TridentCmboBx). I can not seem to locate much
    >>>>> documentation or even code examples. I am using C#.
    >>>>>
    >>>>> Thanks
    >>>>>
    >>>>> Matt
    >>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Stoitcho Goutsev \(100\), Apr 5, 2006
    #7
  8. ME

    ME Guest

    Enlightening. Thanks for your response Stoitcho. I think I will use the
    index then to "uniquely" identify. Any way I could see an example in C# for
    CB_GETLBTEXT? I think I have it but the method does not work with internet
    explorer's trident combo. All it seems to give is giberish. It seems to
    work with windows forms.

    Here is what I am doing to get the list values:

    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;
    }


    "Stoitcho Goutsev (100)" <> wrote in message
    news:%...
    > Matt,
    >
    > you can attach a user data which is 32 bit number. What this number means
    > is up to you. It could be a number or it could be a pointer to a bigger
    > data structure. Ususally this is used in the case of owner-drawn
    > comboboxes when the style CBS_HASSTRINGS is not set.
    >
    >
    > I'm pretty sure WindowsForms uses that for keeping references with the
    > items, but I doubt it has anything to do with the vlue and display members
    >
    >
    > Stoitcho Goutsev (100)
    >
    > "ME" <> wrote in message
    > news:...
    >> Thanks for your input. What would the "CB_GETITEMDATA" message do then?
    >> It appears that the "CB_GETLBTEXT" message retrieves the text value of
    >> the item. I can not seem to find any examples of "CB_GETITEMDATA" being
    >> used.
    >>
    >> http://msdn.microsoft.com/library/d...reference/comboboxmessages/cb_getitemdata.asp
    >>
    >> Thanks,
    >>
    >> Matt
    >>
    >>
    >> "Stoitcho Goutsev (100)" <> wrote in message
    >> news:exzJFn%...
    >>> Matt,
    >>>
    >>> You cannot read it from Windows native API. They don't exist there.
    >>> Native windows combobox control has only one value and this is the text
    >>> that you see. DisplayMember and ValueMember are part of the .NET
    >>> control.
    >>>
    >>>
    >>> --
    >>>
    >>> Stoitcho Goutsev (100)
    >>>
    >>> "ME" <> wrote in message
    >>> news:...
    >>>> Please forgive my use of the wrong term. ValueMember and DisplayMember
    >>>> are used to BIND the values in .NET combobox on form, however in Visual
    >>>> Basic 6 you had ItemData and List. In ASP.NET you have Text and Value
    >>>> properties of the Item object (DropDownList.Items[x]). The point is
    >>>> there are many ways to make a combo have two corresponding values, a
    >>>> display version (text) and an underlining programmatic version (value).
    >>>> I would like to know how to read both sets of data from a combo using
    >>>> the windows api.
    >>>>
    >>>> I have a web page which I need to generate a new UI for. Unfortunately
    >>>> the page can not be modified by me, the end user. The page contains
    >>>> combos (or dropdownlists) that have items in no logical order (over 100
    >>>> items). I want to display a form to a user with the same list, just
    >>>> alphabetized. When a user selects the item in my list I want to
    >>>> programmatically select the item in the original mixxed up list. I
    >>>> want to make sure that if any value in the list has the same display
    >>>> TEXT, that I will be able to determine which one is which based on the
    >>>> other itemVALUE associated with it.
    >>>>
    >>>> The need for a windows forms version is because this also occurs a
    >>>> windows form appliction with a similar problem. The programmers were
    >>>> idiots and it will be at least a year before they even think about
    >>>> fixing thier list boxes. I want to write a app to work with both.
    >>>>
    >>>> Thanks,
    >>>>
    >>>> Matt
    >>>>
    >>>> "Stoitcho Goutsev (100)" <> wrote in message
    >>>> news:...
    >>>>> Matt,
    >>>>>
    >>>>> What are these ListItemValue and ListItemText on the WindowsForms'
    >>>>> combobox?
    >>>>>
    >>>>>
    >>>>> --
    >>>>>
    >>>>> Stoitcho Goutsev (100)
    >>>>>
    >>>>> "ME" <> wrote in message
    >>>>> news:...
    >>>>>>I am new to interop services as well as the Windows API in general.
    >>>>>>What is
    >>>>>> the proper way to obtain the ListItemValue and the ListItemText using
    >>>>>> the
    >>>>>> windows API? I would like to be able to read a combo's list values
    >>>>>> from a
    >>>>>> windows form application (ComboBox) and also from a combo on a web
    >>>>>> page
    >>>>>> (Internet Explorer_TridentCmboBx). I can not seem to locate much
    >>>>>> documentation or even code examples. I am using C#.
    >>>>>>
    >>>>>> Thanks
    >>>>>>
    >>>>>> Matt
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    ME, Apr 5, 2006
    #8
    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. Metalone

    ctypes pointers and SendMessage

    Metalone, May 31, 2006, in forum: Python
    Replies:
    2
    Views:
    430
    Metalone
    Jun 1, 2006
  2. Replies:
    3
    Views:
    2,086
  3. dthmtlgod

    Fill Combo Box based on another Combo Box

    dthmtlgod, Nov 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    594
    Bob Barrows [MVP]
    Nov 16, 2005
  4. Maxim Ap
    Replies:
    2
    Views:
    367
    Maxim Ap
    Feb 2, 2011
  5. SM
    Replies:
    2
    Views:
    372
Loading...

Share This Page