Click here to Skip to main content
11,640,861 members (61,465 online)
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 20: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 Mika Wendelius 380
1 OriginalGriff 205
2 DamithSL 153
3 CPallini 125
4 Afzaal Ahmad Zeeshan 124
0 Mika Wendelius 370
1 OriginalGriff 205
2 CPallini 125
3 DamithSL 105
4 Afzaal Ahmad Zeeshan 70


Advertise | Privacy | Mobile
Web04 | 2.8.150731.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