LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


I have the following code in c#:
Code:
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
			DrawTopLabel(g);

			// 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;
				dataGridPrinter1.PageNumber++;
			}
		}

		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)
			{
				printDocument1.Print();
			}


		}

		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
tekkieman
Member
 
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"];
 
  


Reply


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 vb.net 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


All times are GMT -5. The time now is 01:54 PM.

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