Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-27-2006, 10:01 AM   #1
Registered: May 2005
Posts: 275

Rep: Reputation: 30
Printing a datagrid/dataset in c#

I have the following code in c#:
void SetupGridPrinter()
dataGridPrinter1 = new DataGridPrinter(dgQueryResults, printDocument1, Dataset1);
		private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
			Graphics g = e.Graphics; 
			// Draw  a label title for the grid

			// draw the datagrid using the DrawDataGrid method passing the Graphics surface
			bool more = dataGridPrinter1.DrawDataGrid(g);

			// if there are more pages, set the flag to cause the form to trigger another print page event
			if (more == true)
				e.HasMorePages = true;

		private void btnPrint_Click(object sender, System.EventArgs e)
			// Initialize the datagrid page and row properties
			dataGridPrinter1.PageNumber = 1;
			dataGridPrinter1.RowCount = 0;

			// Show the Print Dialog to set properties and print the document after ok is pressed.
			if (printDialog1.ShowDialog() == DialogResult.OK)


		void DrawTopLabel(Graphics g)
			int TopMargin = printDocument1.DefaultPageSettings.Margins.Top;

			//g.FillRectangle(new SolidBrush(label1.BackColor), label1.Location.X, label1.Location.Y + TopMargin, label1.Size.Width, label1.Size.Height);
			//g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), label1.Location.X + 50, label1.Location.Y + TopMargin, new StringFormat());
I am getting an error on the boldered area of code stating that I cannot conert a dataset to a data table. What needs to be done to fix this?
Old 02-27-2006, 03:43 PM   #2
Registered: Dec 2004
Location: Northern CA
Distribution: Mepis 6.5
Posts: 123

Rep: Reputation: 15
The dataGridPrinter object wants a datatable. You passed a dataset. An implicit cast is not allowed, although they are not really the same things anyway. The dataset can contain datatables. Does dataGridPrinter really take a datagrid object as a parameter? If it does, passit the correct datatable from the dataset object such as:

Instead of "Dataset1", use "Dataset1.Tables["tableName"];


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mono and Datagrid Vagrant Programming 1 02-23-2006 12:35 AM
Displaying an oracle dataset on a datagrid using C# mrobertson Programming 1 01-11-2006 02:34 PM
highlightling certain rows of a datagrid mrobertson Programming 7 08-11-2005 07:48 AM
Querying for data and porinting to a datagrid based on items in a list box mrobertson Programming 8 07-29-2005 01:23 PM
Scribus Printing How to put 4 flyers on a page when printing jazzboy Linux - Software 0 05-02-2004 06:13 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:02 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration