Click here to Skip to main content
Rate this: bad
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
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:[^].
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.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,587
3 Zoltán Zörgő 3,406
4 Richard MacCutchan 2,397

Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2015
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