The .NETCF ComboBox control doesn't have the FindStrind method which is present on the desktop however this is just a wrapper for a windows message supported by the native control so it is possible to wrap it quite easily in .NETCF 2.0 and above. First you need to define the windows message constant:-
internal const int CB_FINDSTRING = 0x14c;
Then you can P/Invoke SendMessage:-
[DllImport("coredll.dll")]
internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, string lParam);
With a little more work you can utilize the existing SendMessage method in Microsoft.WindowsCE.Forms but taking this approach allows us to define the argument types specifically for this purpose.
To use this method pass in the handle to the ComboBox (e.g. comboBox1.Handle), the message constant, the starting index to search from (e.g. -1 to search the whole list) and finally the string to match terminated with a null character e.g.
int index = SendMessage(comboBox1.Handle, CB_FINDSTRING, -1, "Cheese\0");
The method will return either the item index which first matches this value (0 to the number of items -1) or -1 if not found.
To use this on Smartphone you need to use an alternative message since the managed ComboBox control wraps a native listbox:-
internal const int LB_FINDSTRING = 0x018F;

Read the complete post at http://feeds.feedburner.com/~r/PeterFoot/~3/331837940/implement-findstring-for-a-combobox.aspx
Posted
Jul 10 2008, 11:25 AM
by
Peter Foot