Link to home
Start Free TrialLog in
Avatar of jvoros1
jvoros1

asked on

C# Printing a DataGrid

Hello Expert is there an easy way to print the dataGrid when the user hits print on a Windows From  and only the columns that are visible not all the ones that are hidden?

Janka
Avatar of Joeisanerd
Joeisanerd

did you still want to print all of the rows? When you use a dataGrid and limit the number of columns to display it creates a dataview. You would then use that dataview to print only the data that is shown.

You could also use Crystal Reports to make the data layout look better for printing.
Avatar of jvoros1

ASKER

Do you have anywhere a sample of code to show me by any chance I am pretty new to C# and I never printed before.
Avatar of jvoros1

ASKER

this Is an example of my dataGrid binding
                  cs = new DataGridTextBoxColumn();
                  cs.MappingName = "PermitApprov";
                  cs.HeaderText = " Permit / Approve. Etc ";
                  cs.Width = 200;
                  cs.Alignment = HorizontalAlignment.Center;
                  tableStyle.GridColumnStyles.Add(cs);
                  dataGrid1.TableStyles.Add(tableStyle);

                  cs = new DataGridTextBoxColumn();
                  cs.MappingName = "UserID";
                  cs.HeaderText = " User ID";
                  cs.Width = 0;
                  cs.Alignment = HorizontalAlignment.Center;
                  //Sets the Default Value of userID
                  aDataSet.Tables["tbl_ProjectLogDrawingsInOut"].Columns["UserID"].DefaultValue = 0;
                  tableStyle.GridColumnStyles.Add(cs);
                  dataGrid1.TableStyles.Add(tableStyle);

                  dataGrid1.DataSource = aDataTable;
ASKER CERTIFIED SOLUTION
Avatar of glsac
glsac
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial