Select to view content in your preferred language

Printing a Table of Query Results

1991
8
02-23-2011 09:11 AM
LaneHartman
Emerging Contributor
Is there a script, add-in or some other way to print out the table of results when using the Query Features or QueryPlus Add-in?
0 Kudos
8 Replies
EdanCain
Deactivated User
Lane,
I haven't time currently to update the Query Features addin and this is the first request for printing capability for the result table.
If there is more interest in such functionality I might be convinced to do it.

Edan
0 Kudos
LaneHartman
Emerging Contributor
I understand. I wouldn't mind giving it a try myself if I was pointed in the right direction. Are there any help files or examples of other print add-ins that I could start from?  I've started looking at some of the web api examples to see if I could get some clues from there.  Thanks for taking the time to reply.
0 Kudos
EdanCain
Deactivated User
Hi Lane,
the table that you see with results is a DataGridView. Here is a good link as to how to print the contents of a DataGridView.
http://www.xmlfox.com/print_datagridview.htm

All I am doing is applying an SQL query to the FeatureLayer. (RowCollection myRowCollection = FeatureLayer::Table::Search(myQuery)).

Once you have your RowCollection, iterate through it populating a DataTable and bind the DataGridView.DataSource to the dataTable.

Or, wait until I get some time to update the addin.

Hope this helps,
Edan
0 Kudos
LaneHartman
Emerging Contributor
Thanks for pointing me in the right direction. I think I'm almost there, but I can't figure out what "type" needs to go in the code highlighted in red below. I keep getting the error "Type 'frmPrint' is not defined." I guess I'll just wait for you to get a chance to update the following code if its not an easy solution. I've attached the VB project as a zip file.


 
Copyright 2010 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions at <your ArcGIS Explorer install location>/DeveloperKit/userestrictions.txt.
' 
 
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports RustemSoft.DataGridViewColumns
Imports System.Drawing.Printing
 
 
Partial Public Class QueryResultsForm
Inherits Form
Public Sub New(ByVal data As ESRI.ArcGISExplorer.Data.TableBindingAdapter)
InitializeComponent()
 
' bind the data grid view to the table binding adapter
dataGridView1.DataSource = data
End Sub
 
Private PrintGrid As DataGridViewPrint
Private Sub buttonPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonPrint.Click
Dim fpr As New frmPrint()
With fpr
.ShowDialog()
If .Result > 0 Then
PrintGrid = New DataGridViewPrint(PrintDocument1, dataGridView1, .bBlackWhite)
PrintGrid.PrintTitle = .bTitle
PrintGrid.Title = .Title
Select Case .Result
Case 1 ' Print
' The Print method prints the DataGridView without using a print dialog.
' Use a PrintDialog when you want to offer the user the ability to choose print settings.
If PrintDialog1.ShowDialog() = DialogResult.OK Then PrintDocument1.Print()
Case 2 ' Page Setup
PageSetupDialog1.ShowDialog()
Case 3 ' Preview
PrintPreviewDialog1.Icon = fpr.Icon
PrintPreviewDialog1.ShowDialog()
End Select
End If
End With
End Sub
 
' Specify the output to print by handling the PrintPage event 
' and by using the Graphics included in the PrintPageEventArgs.
Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
' Print method of DataGridViewPrint class starts the custom DataGridView's printing process.
e.HasMorePages = PrintGrid.Print(e.Graphics)
End Sub
 
End Class
0 Kudos
EdanCain
Deactivated User
Lane,
that sample sorry relies on a custom form, so not so good if you can't implement it.
Had a very quick look online to see if I could spot something of more help for you.
This should solve it for you I think: http://social.msdn.microsoft.com/Forums/en/Vsexpressvb/thread/ad28f68f-7a3d-44c7-a960-888c47d26fda

I have added the code to the project that you sent through and it prints out a quick query I made.

All the best,
Edan
0 Kudos
LaneHartman
Emerging Contributor
That is great! Worked the first time.  Now I just have to work on formatting the table and setting some of the columns as not visible. Thanks so much.

Lane
0 Kudos
EdanCain
Deactivated User
Glad it worked. Always easier when I have code to look at. Should have had a closer look at that first link I sent through and found you something more readily workable.

Have a good day Lane,
Edan
0 Kudos
LaneHartman
Emerging Contributor
Is there any way to specify which columns are visible in dataGridView?
0 Kudos