|
I have managed to include a DataGridView in an MFC-based
dialog but I can't figure out how to put column headings
in it or populate it with data.
Anyone have any snippets of code that can do the trick ?
|
|
|
|
|
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: BindingContext Class (System.Windows.Forms) Control.BindingContext Property (System.Windows.Forms)
Quoted from A problem with using DataGridView control in an MFC CDialog
|
|
|
|
|
I must have missed something. The .Net assemtly winform thing (I'm new to all this .net stuff, so bear with me) loads up fine, but it's just black. The background of the control is usually black, so it's like the rest of it isn't drawn. I should also be able to right click on the control it's self and get a menu to configure the control. I've been struggling with this all day and can't figure it out.
|
|
|
|
|
Hello Nish,
I want to ask you the things. I dont have VC++ 2005 but I want to buy it. Before buying I just want to confirm some of the follwoing things.
1. I have a large project written in MFC VC6. Can I do further modification in that project?
2. Can I convert whole MFC base project in to Form base project ?
Thank you
Mahesh
|
|
|
|
|
Hello Mahesh
msonawane wrote: 1. I have a large project written in MFC VC6. Can I do further modification in that project?
Yes, you can convert the project to VC++ 2005 (a wizard pops up automatically) and you can continue modifying it as a pure native project. Depending on how good your code was, the transition may involve varying levels of difficulty. The VC6 compiler was pretty bad, while the 2005 compiler is among the best C++ compilers out there in terms of ISO C++ compliance. So, you may find that some of your old code will have to be rewritten to confirm to the newer/stricter compiler.
msonawane wrote: 2. Can I convert whole MFC base project in to Form base project ?
That will not be easy, as you would manually have to port it to Windows Forms. Also, since WPF is around the corner, you may want to wait till WPF is out, and then port to that instead of to Forms which is just a transient (IMHO) technology.
Regards,
Nish
|
|
|
|
|
Hello Nish,
Thank you very much for valuable information.
Have a nice day.
Regards
Mahesh
|
|
|
|
|
Nice article Nishant.
I was already looking for such this solution.
|
|
|
|
|
Thanks, Majid
|
|
|
|
|
Hi Nish...
Great work. Uptill now, we were looking at this[^]
way of doing this. Microsoft has yet again made it easier to handle. I am looking forward to VC 8.0 now :->
|
|
|
|
|
Yep, it was far tougher and basically a pain in the ass to do this in VC++ 2003. VC++ 2005 has made it real nice and easy for us
|
|
|
|
|
Congratulations Nishant! Had there not been a giant ocean between us, the beer would have been on me!
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Heh
Thanks Jörgen
|
|
|
|
|
congrets !....A Century
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thanks, Alok
|
|
|
|
|
Hi,
I have this code for connecting to SQL Server:
CString sql;
CDatabase m_database ;
sql.Format("DRIVER=SQL Server;SERVER=myserver;DATABASE=test;UID=administrator; PWD=admin;Trusted_Connection=No");
m_database.SetLoginTimeout(10);
m_database.SetQueryTimeout(10);
TRY{
m_database.OpenEx (sql,CDatabase::noOdbcDialog );
}
CATCH(CDBException, e){
m_database.Close();
MessageBox("Connection failed");
}
END_CATCH
I am connecting to a remote sql server. This code works fine if I'm connected in the network and i was able to catch the Exception, however, when I disconnect the host pc from network, an unknown exception was thrown. "Unknown software exception (0x0000409)..." . Is there any way to catch this exception ? It also happen when I mispelled the server name.
Mar Solero Jr.
|
|
|
|
|
What made you post this here? Your question should be posted in the Visual C++ forum.
|
|
|
|
|
Sorry..got a mistake...I'll post it to Visual C++ forum.
Thanks!
Mar Solero Jr.
|
|
|
|
|
mhar wrote: Sorry..got a mistake...I'll post it to Visual C++ forum.
Thanks!
No problem
|
|
|
|
|
Yes, it is easy to do so in VS 2005. Is the reverse process also supported.. i.e hosting MFC control on the Winform window ? There are such articles present here but they dated back to VS 2001 to VS 2003. I like to know whether in VS 2005, this process is easier or not ?
Imtiaz
|
|
|
|
|
Imtiaz Murtaza wrote: Yes, it is easy to do so in VS 2005. Is the reverse process also supported.. i.e hosting MFC control on the Winform window ? There are such articles present here but they dated back to VS 2001 to VS 2003. I like to know whether in VS 2005, this process is easier or not ?
No, there aren't any classes available (as far as I know) that let you put an MFC control into a WinForms form.
|
|
|
|
|
CWinFormsControl : This is cool, thanks !!!
now if I can get my IT guys to install a version of VS.2005... and try experimenting.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Maximilien wrote: now if I can get my IT guys to install a version of VS.2005... and try experimenting.
Show them my article :->
|
|
|
|
|
dear nish,
i respect you and you very powerful contribution to CodeProject ; am' sure also i will find in you voice the answer i am looking for.
well, here is the point.
for me, Managed an unmanaged code are two things different, and even if they can be mixed up (use unmanaged things in MC++ and vice versa), i still cannot understand why people would do so.
In fact, maybe i think a bit too much as in java world, but isn't .NET framework supposed to let programs run on whatever plateform (windows independant so), at the only condition that the framework is installed ? can't a managed program run either on a linux, mac, sunOS, windows computer if the framework is there ?
if so, then why would a programmer mix managed code with unmanaged, which is by definition a code that is plateform dependant, that can run on only one machine with a compilation state ?
i'm quite sure you have your reasons in this, that's why i'm waiting with a great attention to what you say...
thank you
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
Imagine a company that has a 500,000 lines of code MFC application. Imagine that they want to use this hyper cool .NET UI library to give all their applications a new look and feel, and to also take advantage of the massive .NET class libraries.
They have 3 options
(1) Rewrite a 500,000 lines of code native app to .NET, and then use the .NET stuff.
[bad idea as you can see]
(2) Ignore .NET and continue using their MFC codebase to add new features.
[bad idea in the long run; apps continue to look old; cannot take advantage of new .NET classes]
(3) Mix native code with .NET using C++/CLI
[definitely a better idea than (1) and (2)]
That's my answer, Toxcct! I don't know if everyone agrees with me there. But as long as there are customers for that sort of thing, Microsoft will (and should) continue to enhance mixed-mode support in their C++ compiler.
|
|
|
|
|
ok, so, as you say, it better for reuse (instead os rewrite so) an old/existing code...
so you agree with me that the code won't be as portable as if it was written in pure MC++ right ??
thx for the answer anyway.
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|