Click here to Skip to main content
11,584,208 members (64,259 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 OriginalGriff 430
1 Sergey Alexandrovich Kryukov 369
2 Dave Kreskowiak 260
3 Richard Deeming 220
4 virusstorm 194
0 OriginalGriff 1,663
1 Sergey Alexandrovich Kryukov 1,229
2 Abhinav S 701
3 Dave Kreskowiak 667
4 Suvendu Shekhar Giri 568


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