Jump to content

printpreview for datagridview

- - - - -

  • Please log in to reply
8 replies to this topic

#1
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
hy i'm using .mdf table...in source i'm using sql query for creating tables (database is created in SQL Server Management Studio...all i want is when i click on button "print" that i have print preview of dataGridView table...i know how to get printpreview but i don't know how to connect datagridview to printpreview...table is named Tehnicar_za_racunalstvo...and i get values in table from textBox controls...that's all information i can give

this is the line from which i get print preview


printPreviewDialog1.ShowDialog();

any help???

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
This tutorial should help you. :)
How To Print a Data Grid in C# and .NET

~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
i have created columns using xml
so i need to create a new row in dataGridView control with mouse click on button for creating a new row...
i've seen so many tuttorials but neither helped me...
first i need to open that xml into dataGridView (my xml file is named Teh_za_rac.xml)
and then i should add a new row in that table by click on button
my dataGridView is named Tablica1
can you please help me

#4
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
no matters i've done it

#5
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
sorry Committed but i didn't understand that tutorial
i don't know what to do, this is the final thing for my project

#6
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
you should check out crystal reports
I think that's what you want. It wouldn't print or offer print preview from the data grid view,
but it would from the underlying database. That's what you want.

Crystal Reports ships with Visual Studio, so you should just be able to add a report to your application
Then you can use a Crystal Reports Viewer, and load the report. The viewer has all the preview and print functionality you need. It even allows you to customize the report, to your liking, with pretty much everything you could imagine.

#7
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
can you give me site where i can learn what crystal report is, few examples,...
and can you teach me technique how to save values from datagridview into mdf database

#8
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
i have finished that print preview with DGVPrinter...check on google
and my program works well when i'm sorting rows with Bodovi column (i've put xml into dataGridView so it opens table when i click on Button Stvori)
this is code for my Button Stvori

private void button1_Click(object sender, EventArgs e)

        {


            XmlDataDocument xmlDatadoc = new XmlDataDocument();

            xmlDatadoc.DataSet.ReadXml("C:\\EtsDtb\\EtsDtb\\bin\\Debug\\Elektrotehnicar.xml");

            DataSet ds = new DataSet("Tablica");

            ds = xmlDatadoc.DataSet;

            Tablica1.DataSource = ds.DefaultViewManager;

            Tablica1.DataMember = "Elektrotehničar";

        }

and to not forget to tell my problem is when i click on column name Bodovi it sometimes gives me error and error says that if i want to countinue working in program i have to click continue and if not i have to click quit...but when i click continue it erase everything from table so i lost all my informations...how can i fix it???
here is XML code if you need it

<?xml version="1.0" encoding="utf-8" ?>

<Ime>

  <Elektrotehničar>

    <Ime> </Ime>

    <Prezime> </Prezime>

    <Datum_Rođenja> </Datum_Rođenja>

    <Učeni_Jezik> </Učeni_Jezik>

    <Religijski_Predmet> </Religijski_Predmet>

    <Dodatni_Bodovi> </Dodatni_Bodovi>

    <Br_Dod_Bodova> </Br_Dod_Bodova>

    <Matematika_7> </Matematika_7>

    <Matematika_8> </Matematika_8>

    <Hrvatski_7> </Hrvatski_7>

    <Hrvatski_8> </Hrvatski_8>

    <Strani_Jezik_7> </Strani_Jezik_7>

    <Strani_Jezik_8> </Strani_Jezik_8>

    <Fizika_7> </Fizika_7>

    <Fizika_8> </Fizika_8>

    <Teh_Kultura_7> </Teh_Kultura_7>

    <Teh_Kultura_8> </Teh_Kultura_8>

    <Prosjek_7> </Prosjek_7>

    <Prosjek_8> </Prosjek_8>

    <Ponavljač> </Ponavljač>

    <Bodovi> </Bodovi>



  </Elektrotehničar>

</Ime>

i need to fix it so i can finally be finished with my program

#9
saviolan

saviolan

    Newbie

  • Members
  • Pip
  • 1 posts
C# datagridview printing source code

C# DataGridView Printing

savs.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users