Can't determine correct type at runtime

B

Bill Fuller

I am trying to determine the type for ActiveControls using 3rd party
controls (Infragistics in this case) during runtime and getting a rather odd
return type at runtime for the UltraWinEditor.

Code shippet is as follows:

if ( ActiveControl.GetType() == typeof(UltraTextEditor))
{
UltraTextEditor tb = (UltraTextEditor) this.ActiveControl;
if (tb.Multiline == true)
return true;
}

I am expecting to see an UltraTextEditor for the ActiveControlType but,
instead, getting "Infragistics.Win.EmbeddableTextBoxWithUIPermissions", so
the "if" statement fails on the control.

If I modify the "if" statement to: "if (ActiveControl.GetType().ToString()
== "Infragistics.Win.EmbeddableTextBoxWithUIPermissions")", the subsequent
cast fails.

Does anyone know what would cause the control type to be different at
runtime than what it was built from?

(BTW, the test form is ONLY using UltraTextEditor controls, so the type
should be the same for each.)
 
L

Lasse Vågsæther Karlsen

Bill said:
I am trying to determine the type for ActiveControls using 3rd party
controls (Infragistics in this case) during runtime and getting a rather odd
return type at runtime for the UltraWinEditor.

Code shippet is as follows:

if ( ActiveControl.GetType() == typeof(UltraTextEditor))
{
UltraTextEditor tb = (UltraTextEditor) this.ActiveControl;
if (tb.Multiline == true)
return true;
}

I am expecting to see an UltraTextEditor for the ActiveControlType but,
instead, getting "Infragistics.Win.EmbeddableTextBoxWithUIPermissions", so
the "if" statement fails on the control.

If I modify the "if" statement to: "if (ActiveControl.GetType().ToString()
== "Infragistics.Win.EmbeddableTextBoxWithUIPermissions")", the subsequent
cast fails.

Does anyone know what would cause the control type to be different at
runtime than what it was built from?

(BTW, the test form is ONLY using UltraTextEditor controls, so the type
should be the same for each.)

I'm going on assumptions here, but judging by the full name of that
control, I'd say you have focus to the editor, but it is actually
similar to a user control and what you're reading there is an embedded
editor inside what dropped on the form.

DevExpresses uses the same approach, with something like a
RepositoryTextEdit, which is then used internally in both grids and
normal droppable edit controls. I don't know if the DevExpress controls
would give me the same behavior as you're seeing though.

In any case, it's just a guess. I guess the best way to get a concrete
answer would be to ask the Infragistics guys about this.

Let me pose another question... What specifically are you trying to
accomplish with the code? Perhaps there's a different way to do what you
want to do than the one you're currently trying.
 
G

Gilles Kohl [MVP]

I am trying to determine the type for ActiveControls using 3rd party
controls (Infragistics in this case) during runtime and getting a rather odd
return type at runtime for the UltraWinEditor.

Code shippet is as follows:

if ( ActiveControl.GetType() == typeof(UltraTextEditor))
{
UltraTextEditor tb = (UltraTextEditor) this.ActiveControl;
if (tb.Multiline == true)
return true;
}

I am expecting to see an UltraTextEditor for the ActiveControlType but,
instead, getting "Infragistics.Win.EmbeddableTextBoxWithUIPermissions", so
the "if" statement fails on the control.

If I modify the "if" statement to: "if (ActiveControl.GetType().ToString()
== "Infragistics.Win.EmbeddableTextBoxWithUIPermissions")", the subsequent
cast fails.

Does anyone know what would cause the control type to be different at
runtime than what it was built from?

(BTW, the test form is ONLY using UltraTextEditor controls, so the type
should be the same for each.)

Hmm, could it be that UltraTextEditor is a composite control,
containing an Infragistics.Win.EmbeddableTextBoxWithUIPermissions at
runtime?

As the latter seems to be derived from TextBox according to:

http://help.infragistics.com/Help/N...8.1~Infragistics.Win_namespace_hierarchy.html

what you could do instead of your if block above is this (untested):

TextBox tb = ActiveControl as TextBox;
if(tb != null) {
if(tb.Multiline) {
return true;
}
}

Regards,
Gilles.
 
B

Bill Fuller

Lasse Vågsæther Karlsen said:
I'm going on assumptions here, but judging by the full name of that
control, I'd say you have focus to the editor, but it is actually similar
to a user control and what you're reading there is an embedded editor
inside what dropped on the form.

DevExpresses uses the same approach, with something like a
RepositoryTextEdit, which is then used internally in both grids and normal
droppable edit controls. I don't know if the DevExpress controls would
give me the same behavior as you're seeing though.

In any case, it's just a guess. I guess the best way to get a concrete
answer would be to ask the Infragistics guys about this.

Let me pose another question... What specifically are you trying to
accomplish with the code? Perhaps there's a different way to do what you
want to do than the one you're currently trying.

--
Lasse Vågsæther Karlsen
mailto:[email protected]
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

It sounds like you are pointing me in the right direction as to the source
of my problem. I did post the question to Infragistics, but need to find an
answer ASAP, if possible, and I have found them to be rather slow in
responding.

What I am trying to do (and it is working for the most part) is set a global
hook via IMessageFilter to convert the ENTER key to a TAB key for the entire
application, which is largely data entry type forms. However, I have also
set a virtual method for this that can be overridden in instances where the
Enter key on a particular form needs to be processed rather than use the
default, such as in the case where a multiline textbox that allows Enter key
handling may be on the form... or perhaps a button key. This code would
process the override if I can get it to work... was taken by surprise with
the type return as a standard Microsoft textbox works as expected.
 
B

Bill Fuller

Gilles Kohl said:
Hmm, could it be that UltraTextEditor is a composite control,
containing an Infragistics.Win.EmbeddableTextBoxWithUIPermissions at
runtime?

As the latter seems to be derived from TextBox according to:

http://help.infragistics.com/Help/N...8.1~Infragistics.Win_namespace_hierarchy.html

what you could do instead of your if block above is this (untested):

TextBox tb = ActiveControl as TextBox;
if(tb != null) {
if(tb.Multiline) {
return true;
}
}

Regards,
Gilles.

Your untested code fix did the trick...thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top