Michael
Fri Dec 23 06:27:08 CST 2005
Very promising...
Uh, but it doesn't work :( I get the same behavior. In the WndProc, I set
the combobox Text property. But the text is then switched back. Below is
my code.
I correctly enter the block where I change the text and can view that the
text was actually changed (using the debugger). After I set the text, the
system is setting it.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
// Listen for operating system messages.
if (m.Msg == Constants.WM_COMMAND)
{
IntPtr handle = (IntPtr) m.LParam;
if (handle == MyComboBox.Handle)
{
if (((int) m.WParam & ~0xffff) == Constants.CBN_SELCHANGE)
{
MyComboBox.Text = "Hello!";
return;
}
}
}
base.WndProc(ref m);
}
--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:1B61B436-C47A-425C-A2B2-4EE2969912BB@microsoft.com...
> Hi Michael,
>
> "Michael J. Salamone" wrote:
>
>> Reposting to a larger audience - hope someone can help!
>>
>> This may seem a bit odd, but I'd like to set the text in a ComboBox
>> control
>> when an item is selected from the drop down list. I want the text to be
>> different than the display text of the selected item.
>>
>> For example, if "x" is the display text of the selected item, I want the
>> text in the text box to be set to "y".
>>
>> I tried changing the text on SelectedIndexChanged event, but the text is
>> set
>> (by the control) to the display text of the selected item *after* this
>> event. I've also tried TextChanged (same problem as SelectedItemChanged)
>> and TextUpdate (but this only fires when the user enters text directly in
>> the text box).
>>
>> In Win32, I do this at WM_COMMAND/CBN_SELCHANGE time, which I would have
>> thought equates to SelectedIndexChanged in the .NET Framework.
>>
>> Any ideas?
>> --
>> Michael Salamone [eMVP]
>> Entrek Software, Inc.
>> www.entrek.com
>
> Handle the win32 events you mention from .NET code. Override the
> Control.WndProc method and handle the events you mention (in that case
> don't
> delegate to base class implementation).
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasswndproctopic.asp
>
> Kind regards,
> --
> Tom Tempelaere.
>