Home All Groups Group Topic Archive Search About

How to get ListItemValue and ListItemText from a Combo using SendMessage

Author
3 Apr 2006 6:41 PM
ME
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

Author
3 Apr 2006 7:10 PM
Stoitcho Goutsev (100)
Matt,

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


--

Stoitcho Goutsev (100)

Show quoteHide quote
"ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
news:1JadnTmZVdj18azZnZ2dnUVZ_tednZ2d@comcast.com...
>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
>
>
>
Author
3 Apr 2006 7:55 PM
ME
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

Show quoteHide quote
"Stoitcho Goutsev (100)" <1**@100.com> wrote in message
news:ukOrwG1VGHA.4596@TK2MSFTNGP15.phx.gbl...
> Matt,
>
> What are these ListItemValue and ListItemText on the WindowsForms'
> combobox?
>
>
> --
>
> Stoitcho Goutsev (100)
>
> "ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
> news:1JadnTmZVdj18azZnZ2dnUVZ_tednZ2d@comcast.com...
>>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
>>
>>
>>
>
>
Author
4 Apr 2006 1:19 PM
Stoitcho Goutsev (100)
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)

Show quoteHide quote
"ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
news:-MKdnQbhT4Yg4KzZ4p2dnA@comcast.com...
> 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)" <1**@100.com> wrote in message
> news:ukOrwG1VGHA.4596@TK2MSFTNGP15.phx.gbl...
>> Matt,
>>
>> What are these ListItemValue and ListItemText on the WindowsForms'
>> combobox?
>>
>>
>> --
>>
>> Stoitcho Goutsev (100)
>>
>> "ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
>> news:1JadnTmZVdj18azZnZ2dnUVZ_tednZ2d@comcast.com...
>>>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
>>>
>>>
>>>
>>
>>
>
>
Author
4 Apr 2006 9:24 PM
ME
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/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxreference/comboboxmessages/cb_getitemdata.asp

Thanks,

Matt


Show quoteHide quote
"Stoitcho Goutsev (100)" <1**@100.com> wrote in message
news:exzJFn%23VGHA.5916@TK2MSFTNGP12.phx.gbl...
> 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" <trash.trash@comcast.netREMOVETHIS> wrote in message
> news:-MKdnQbhT4Yg4KzZ4p2dnA@comcast.com...
>> 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)" <1**@100.com> wrote in message
>> news:ukOrwG1VGHA.4596@TK2MSFTNGP15.phx.gbl...
>>> Matt,
>>>
>>> What are these ListItemValue and ListItemText on the WindowsForms'
>>> combobox?
>>>
>>>
>>> --
>>>
>>> Stoitcho Goutsev (100)
>>>
>>> "ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
>>> news:1JadnTmZVdj18azZnZ2dnUVZ_tednZ2d@comcast.com...
>>>>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
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
4 Apr 2006 11:14 PM
Stoitcho Goutsev (100)
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)

Show quoteHide quote
"ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
news:2uednVzx1qtufq_ZnZ2dneKdnZydnZ2d@comcast.com...
> 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/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxreference/comboboxmessages/cb_getitemdata.asp
>
> Thanks,
>
> Matt
>
>
> "Stoitcho Goutsev (100)" <1**@100.com> wrote in message
> news:exzJFn%23VGHA.5916@TK2MSFTNGP12.phx.gbl...
>> 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" <trash.trash@comcast.netREMOVETHIS> wrote in message
>> news:-MKdnQbhT4Yg4KzZ4p2dnA@comcast.com...
>>> 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)" <1**@100.com> wrote in message
>>> news:ukOrwG1VGHA.4596@TK2MSFTNGP15.phx.gbl...
>>>> Matt,
>>>>
>>>> What are these ListItemValue and ListItemText on the WindowsForms'
>>>> combobox?
>>>>
>>>>
>>>> --
>>>>
>>>> Stoitcho Goutsev (100)
>>>>
>>>> "ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
>>>> news:1JadnTmZVdj18azZnZ2dnUVZ_tednZ2d@comcast.com...
>>>>>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
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
5 Apr 2006 4:45 PM
ME
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;
}


Show quoteHide quote
"Stoitcho Goutsev (100)" <1**@100.com> wrote in message
news:%23Vh40zDWGHA.4924@TK2MSFTNGP05.phx.gbl...
> 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" <trash.trash@comcast.netREMOVETHIS> wrote in message
> news:2uednVzx1qtufq_ZnZ2dneKdnZydnZ2d@comcast.com...
>> 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/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxreference/comboboxmessages/cb_getitemdata.asp
>>
>> Thanks,
>>
>> Matt
>>
>>
>> "Stoitcho Goutsev (100)" <1**@100.com> wrote in message
>> news:exzJFn%23VGHA.5916@TK2MSFTNGP12.phx.gbl...
>>> 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" <trash.trash@comcast.netREMOVETHIS> wrote in message
>>> news:-MKdnQbhT4Yg4KzZ4p2dnA@comcast.com...
>>>> 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)" <1**@100.com> wrote in message
>>>> news:ukOrwG1VGHA.4596@TK2MSFTNGP15.phx.gbl...
>>>>> Matt,
>>>>>
>>>>> What are these ListItemValue and ListItemText on the WindowsForms'
>>>>> combobox?
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Stoitcho Goutsev (100)
>>>>>
>>>>> "ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
>>>>> news:1JadnTmZVdj18azZnZ2dnUVZ_tednZ2d@comcast.com...
>>>>>>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
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
3 Apr 2006 8:04 PM
Weaver2112
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:
Show quoteHide quote
> Matt,
>
> What are these ListItemValue and ListItemText on the WindowsForms' combobox?
>
>
> --
>
> Stoitcho Goutsev (100)
>
> "ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
> news:1JadnTmZVdj18azZnZ2dnUVZ_tednZ2d@comcast.com...
> >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
> >
> >
> >