Why events are behaving differently for controls in 1.0 and 1.1 of .NET?

  • Thread starter Thread starter Anil
  • Start date Start date
A

Anil

Hi all,

I have observed that some of the controls in 1.0 .NET framework behave
differently in 1.1 .NET framework.
For example - the ComboBox control:

The combo box is in DropDown mode. Consider the behavior of KeyPress event.
In 1.0 framework, the combobox Text property contains the modified value
during KeyPress event handling.
For eample, if the text in the combobox is "test" initially and I modified
it to "test1" then in key press event the Text property is "test1".
But this is not the case in 1.1 framework. The Text property is old value
i,e., in this case "test" but not "test1".

private void testComboBox_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Text Value in KeyPress :" +
testComboBox.Text);
}

run this in both 1.0 and 1.1 framework.

Due to this my applications are not working properly when I port them from
1.0 to 1.1 .NET framework.
My main concern is: Is this behavior is a bug or intentionally done ?
Because this is causing problems: Help!!!!

Thanks,
Anil.
 
I have observed that some of the controls in 1.0 .NET framework behave
differently in 1.1 .NET framework.
For example - the ComboBox control:

Anil,

I've observed this inconsistence several months ago and I also posted to
this newsgroup. I've learned that this is perfectly valid change and the 1.0
behaviour was improper.

You just have to live with that.

Regards,
Wiktor

(look at my message)
http://groups.google.com/groups?q=zychla+combobox+semantics+group:microsoft.
public.dotnet.*&hl=pl&lr=&ie=UTF-8&oe=UTF-8&group=microsoft.public.dotnet.*&
selm=%234DuNcNNDHA.4024%40tk2msftngp13.phx.gbl&rnum=2
 
For example in auto completion code, If the text is updated after Keypress
event , then how do we validate the typed value?
We can use the keyUp event to validate. However, if we keep a key pressed
for a moment, many characters will be added to the text (i.e many key press
events will be fired before the actual KeyUp event is fired) and we will get
the handle to KeyEvent after releasing the key.

Can anyone give us a list of such misbehaviors in .NET 1.0 so that we will
consider them while coding?
(Microsoft should have taken the responsibility to bring out these mistakes
in .NET 1.0 and should have posted the list on MSDN/Microsoft website).
It is very unfair on Microsoft by not informing the changes in two versions
of .NET and making developers life miserable.

Thanks,
Ramana
 
Hi Ramana,
I'm not giving you advice because I think you are not really asking for
help. Neither I advocate those silent changes.
But I suppose that the event TextChanged is the event that you should use if
you want to validate the code after the text is changed. If you want to
prevent a wrong symbol even to appear next to the already typed ones you can
hook on KeyPress event and set Handled to *true* if the key is not propper
for the current content of the Text property. I don't see any way to use
KeyDown event for comboboxes since their KeyDown event's *Handled* property
doesn't work this way.

Anyway. I believe the .NET 1.1 behaviour is more correct because now we have
one event for before the text is changed and one for after the actual
changing.

I suppose it would've been better if we had had dedicated event for
*before*. In this event we would be able to check the context compatibility
of the new symbol and leave KeyPress or KeyDawn event for unconditional
blocking some of the keys or something like that.

I can recall Borland changing the events in VCL in a similar way when they
introduced the 5th versions of C++ Builder and Delphi as well as Kylix. And
as far as I know the didn't bring our attention to that. So we had to find
out by our selfs why our perfectly working code with version 4 doesn't work
with the new (fully competible as they advertised) framework. And when I
asked (during one conference) one of the Borland guys he told me: "Those
are *minor* changes". Even more I couldn't find any reasonable explanation
of those changes.


B\rgds
100
 
Hi,
We have faced this problem in one of our projects where we used keydown and
key press events. Now after seeing this thread I have changed the entire
logic in my code and used a flag to work in both 1.0 and 1.1. My real
concern is to know similar undocumented differences in both versions.
Can anyone help me in this regard.

This particular problem is not documented in the article located at
gotdotnet.

Advance Thanks,
Ramana
 
Back
Top