日期:2014-05-18  浏览次数:20819 次

PrintListView 我想打钱ListView,请问这个类如何使用呢?
我现在在WinForm里想要直接打印ListView这个控件,在网上找到一个PrintListView这个类,
说明上说是:无需导入com组件,无需绑定Datatable,将 listview 声明为此类的实例,再直接调用 doprint()方法就可以进行打印了,
类的详细请见这里:http://blog.csdn.net/hemingwang0902/archive/2007/05/18/1615602.aspx


如是,我这样使用
--------------------------------------------------
PrintListView pl=new PrintListView();
pl=(PrintListView)listView1; 
pl.DoPrint();  
--------------------------------------------------


但却报错,有没有哪些位点下这个类怎么用啊??

报错详细信息如下:


未处理 System.InvalidCastException
  Message="无法将类型为“System.Windows.Forms.ListView”的对象强制转换为类型“PrintListView.PrintListView”。"
  Source="AgentAdmin"
  StackTrace:
  在 AgentAdmin.AgentManage.button10_Click(Object sender, EventArgs e) 位置 E:\MyWork\20080514\AgentAdmin1\AgentAdmin1\AgentManage.cs:行号 967
  在 System.Windows.Forms.Control.OnClick(EventArgs e)
  在 System.Windows.Forms.Button.OnClick(EventArgs e)
  在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
  在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
  在 System.Windows.Forms.Control.WndProc(Message& m)
  在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
  在 System.Windows.Forms.Button.WndProc(Message& m)
  在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
  在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
  在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  在 System.Windows.Forms.Application.Run(Form mainForm)
  在 AgentAdmin.Program.Main() 位置 E:\MyWork\20080514\AgentAdmin1\AgentAdmin1\Program.cs:行号 775
  在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
  在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  在 System.Threading.ThreadHelper.ThreadStart()





------解决方案--------------------
最实用的就是设断点调试,看对象内容是什么,都有什么,一般就能使用了
------解决方案--------------------
ListView pl=new PrintListView(); 
pl.DoPrint();