Click here to Skip to main content
13,055,490 members (52,672 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 20: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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2017
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