Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF C#4.0
i am creating wpf application same code below works for printing a datagrid but while printing a datagridview
 
it will throw an error like this Argument 1: cannot convert from System.Windows.Forms.DataGridView to System.Windows.Media.Visual
 
problem i find out is datagridview is an windows form control so anyone knows
 
how to make conversion help me with some ex code or link. thanks in advance
 
PrintDialog dlg = new PrintDialog();

if (dlg.ShowDialog() == true)
{
dlg.PrintVisual(billsearchgrid, "print");//error line billsearchgrid is datagridview name
}
Posted 25-Jun-13 21:30pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You cannot just mix System.Windows.Form and WPF code; those libraries have very different nature. More exactly, you can use Forms controls in WPF application or WPF controls in Forms application, but this is done via the special interop layer which is very complex in its architecture, but it can resolve such problems, which are really quite difficult.
 
You can start with this Microsoft's walkthrough article: http://msdn.microsoft.com/en-us/library/ms751761.aspx[^].
 
This CodeProject article can also be useful: Winforms / WPF Interop[^].
 
However, I would rather advise you to think: do you really need all involved complexity and the hassles? First of all, thing about using pure WPF; usually, this is quite possible.
 
—SA
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 210
3 Afzaal Ahmad Zeeshan 204
4 CPallini 185
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100