DataGrid in a TabPage of a TabControl crashes app

DataGrid in a TabPage of a TabControl crashes app

Post by bWljaGFlb » Sat, 04 Dec 2004 06:39:07


I have a DataGrid within a TabPage of a TabControl which I have integrated
into a customized UserControl(whew!). I have placed this UserControl on a
WindowsForm.

I have found that if I click on a cell/row of the DataGrid and then click on
another(different) application, the original application(the one with the
UserControl) stops responding, fails to repaint and needs to be closed with
the Windows Task Manager. If however, I change the UserControl so that I
don't place the DataGrid in a TabPage of a TabControl, I have no such
problems after I click on a cell/row of the DataGrid and then click on
another application.

Sound familiar to anyone?

--
Michael Hockstein
 
 
 

DataGrid in a TabPage of a TabControl crashes app

Post by bWljaGFlb » Sat, 04 Dec 2004 11:19:04

I left out the MOST important thing! Duh! The UserControl that I described is
placed on a WindowsForm whose code base is VS 2003 C++/MFC. If you place the
UserControl on a WindowsForm that is strictly .NET, there are no problems. I
think that the problem occurs only when this UserControl is consumed by a
C++/MFC application. As I mentioned in the preceding post, it only occurs if
the DataGrid is placed within a TabPage of a TabControl within the
UserControl. If the DataGrid is not placed in a TabPage of a TabControl, the
UserControl will work fine, even in the C++/MFC environment! See the previous
post for directions on how I reproduced the error.

 
 
 

DataGrid in a TabPage of a TabControl crashes app

Post by yhhuan » Sat, 04 Dec 2004 16:37:55

Hello Michael,

Based on my experience, when we create an instance of a Microsoft Windows
Form from a COM client application, the form may behave unexpectedly. For
example, when we create an instance of the form from a Microsoft Visual
Basic 6.0 application or from a Microsoft Foundation Classes (MFC)
application, the focus does not change from one control to another control
when we press TAB. We may also experience unexpected behavior for
keystrokes or for mouse activity.

This behavior occurs because the message loop that the Windows Form uses
and the message loop that the COM client application provides are
fundamentally different.

To make a Windows Form work correctly from a COM client application, you
must run it on a Microsoft .NET Framework message loop. To do this, use one
of the following methods:
1) Use the ShowDialog method to display the Windows Form
2) Display each Windows Form on a new thread
3) Create a shared message loop on a new thread in the .NET Framework
component

For detailed codes on the above methods, you may refer to this KB article:
"You experience unexpected behavior when you use Windows Forms in COM
client applications"
http://www.yqcomputer.com/

By the way, I noticed the following in your description:
"a WindowsForm whose code base is VS 2003 C++/MFC"
"a WindowsForm that is strictly .NET"

Could you describe more on those? Does item2 means a winform application
created by Visual C# application wizard? item1 means a VC++ MFC dialog
based application? (if that, the item1 is not a winform app). If the
problem can not be resolved by the above methods, please create a simple
repro sample and email to me. I will test it on our side and dig more. You
can reach me by removing online from my email address here.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
- http://www.yqcomputer.com/
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
 
 

DataGrid in a TabPage of a TabControl crashes app

Post by bWljaGFlb » Sat, 04 Dec 2004 21:01:04

You seem to have a good appreciation of my situation. It is in fact
unpredictable and often precipitated by the way controls are placed within
one another. Please disregard my poor choice of the word WindowsForm in
reference to COM client applications/MFC. I really restrict myself to .NET
and simply used a term I was familiar with to convey an idea.

If I understood your explanation, to make this work, programatic changes
need to be made on the COM/MFC side of the programming and not on the .NET
side(in other words, I may be able to leave my UserControl as is but modify
the way the control is invoked from within the client app. I possible will be
able to send you an example.

Michael
 
 
 

DataGrid in a TabPage of a TabControl crashes app

Post by bWljaGFlb » Sat, 04 Dec 2004 22:23:02

nother more specific note. My problem is that I have written a UserControl,
not a WindowsForm, therefore one of your suggestions, invoke with ShowDialog,
won't work to display the control.

I haven't pursued the second suggestions, but, creating a UserControl on a
new thread is a different kettle of fish than displaying a WindowsForm on a
new thread.



"michael" wrote:

 
 
 

DataGrid in a TabPage of a TabControl crashes app

Post by yhhuan » Tue, 07 Dec 2004 17:06:08

Hi Michael,

need to be made on the COM/MFC side of the programming and not
is but modify the way the control is invoked from within the client app
That is right. Please test those three workarounds in the KB article to see
whether it helps resolve this issue. I look forward to your testing results.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
- http://www.yqcomputer.com/
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.