Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2006

Tip: Looking for answers? Try searching our database.

A problem with using DataGridView control in an MFC CDialog

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maksim Izbrodin - 16 Jun 2006 17:11 GMT
I have a very simple CDialog-based application (VC++ 8.0/2005), where a
DataGridView control is included through the usage of CWinFormsControl class.
I experience the following problem with this application. If I switch to a
different application (Alt+Tab, for example) while a grid cell is remaining
in editing mode and then go back to my application, the application hangs
(stops responding).

The problem can be reproduced using CWinFormsControl and CWinFormsView
classes, but it is NOT reproducible when using CFrameWnd and CWinFormsView
classes or when using DataGrid control instead of the new DataGridView.

Any ideas what can be the reason of the problem?

P.S.:
If anybody is interested, I can send you a very simple test-application
using which the problem can be easily reproduced.
programmer42 - 19 Jun 2006 21:25 GMT
Hi Maksim,

I'm having a problem replicating your app. Did you any have problems
integrating the DataGridView into the CWinFormsControl< > template?
Because I'm having a problem using the DataGrid/DataGridView within a
MFC dialog.

I created a simple CDialog app (VC++ 8), created a DataSet from an Xml
file and then set it to the DataSource (setting the appropriate table
name as the DataMember), but nothing is displayed in the grid view. I
tried various approaches and data binding options, but nothing seems to
work.

I have no problem setting this up in WinForms - it just won't work in
MFC. I know the data's there because I can actually step right into it
from the DataGrid object (debugger) - it just won't display - the
ColumnCount is still 0.

What's the problem? Did you have this problem?

I'd love to help you, but I can't get past this problem.

> I have a very simple CDialog-based application (VC++ 8.0/2005), where a
> DataGridView control is included through the usage of CWinFormsControl class.
[quoted text clipped - 12 lines]
> If anybody is interested, I can send you a very simple test-application
> using which the problem can be easily reproduced.
Maksim Izbrodin - 20 Jun 2006 09:02 GMT
I had the same problem. Unfortunately, I didn's succeed to understand the
cause of the problem, but I was able to find a workaround for solving it: I
wrapped the DataGridView control in a user control (a control derived from
UserControl class) and then embedded this user control into CWinFormsControl.

My main problem, described in the original post, can be reproduced even
without assigning any data source to the DataGridView and it doesn't depend
on the fact if you embed DataGridView directly to CWinFormsControl or through
a user control.

> Hi Maksim,
>
[quoted text clipped - 8 lines]
> tried various approaches and data binding options, but nothing seems to
> work
.......

> What's the problem? Did you have this problem?
programmer42 - 21 Jun 2006 22:51 GMT
Would it be possible for you to send me your test app?

> I had the same problem. Unfortunately, I didn's succeed to understand the
> cause of the problem, but I was able to find a workaround for solving it: I
[quoted text clipped - 21 lines]
>
> > What's the problem? Did you have this problem?
Maksim Izbrodin - 26 Jun 2006 10:12 GMT
I've got the explanation and solution for both of these problems from
Microsoft Developer Support:

1) When the DataGridView is not data-bound and the user has set the focus to
edit one of the cell’s in the DataGridView and alt-tabs away from the
application and then back, the application hangs.  You would like to know why
this is hanging and how to avoid it.

- This will reproduce with either the data-bound or non-data-bound control,
so long as there is an editable field to accept the keyboard focus.  The
problem occurs when the Dialog attempting to find the default button when it
is activated.  This search goes into an infinite loop.  It starts with the
control with the focus (the edit control inside the DataGridView’s cell) and
searches until it either finds a control which responds to WM_GETDLGCODE with
DLGC_DEFPUSHBUTTON or it gets back to the control it started on.  The problem
is that the DataGridView is not marked as containing focusable child controls
(with the WS_EX_CONTROLPARENT style), and so the dialog doesn’t search into
the DataGridView.  Since it never searches in the DataGridView it doesn’t
find the edit control it started on and never finishes the loop.  If you
watch the application in Spy++ you will see that it is not completely locked
but is forever receiving WM_GETDLGCODE messages.  This can be fixed by adding
the WS_EX_CONTROLPARENT style to the DataGridView.  This can be done external
to the DataGridView by sinking the HandleCreated event or within the
DataGridView by inheriting and overriding CreateParams to add the style.  It
is essentially the same problem as is documented for CPropertySheets in
Q149501.
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsContro
lClassCreateParamsTopic.asp

http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowi
ng/dialogboxes/dialogboxreference/dialogboxmessages/wm_getdlgcode.asp

http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowi
ng/windows/windowreference/windowfunctions/createwindowex.asp

http://support.microsoft.com/?id=149501

2)       When the DataGridView is bound to a DataTable in a DataSet the rows
and columns for that DataTable do not appear in the Grid.

-  This is failing because data-binding requires that the bound control have
a BindingContext.  Normally the DataGridView would use the BindingContext
belonging to the Form it is on, but since the test application’s DataGridView
is on an MFC dialog rather than on a Form it cannot use its parent’s context.
To use data-binding with the MFC-hosted DataGridView will require that the
application either create and manage the BindingContext on its own or host
the DataGridView inside a ContainerControl (such as a UserControl) which will
manage a binding context for its children.  You can find more information
about BindingContexts at:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.bindingcontext.aspx
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.bindingcon
text.aspx


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.