How to print a data grid in visual C#?
Does anyone know how to print a data grid in visual C#? My particular datagrid has close to 50 columns. I have tried the code on MSDN, c sharp corner, and code project but niether seem to account for the additional columnspast the viewable area on the form of the data grid. Hence only 10 columns actually print. Can anyone help me with this?
|
Why not just print it plain-text tab delimited data?
|
How would you go about do that? I am not familiar with that kind of thing.
|
Well, its pretty simple.
Code:
DataTable dt = (DataTable)dataGrid.DataSource; |
Here is the code I am trying to use. I am getting a specified cast is not valid error on the first line of code. What do you see that may be causing this. Is there anything that I need to change or add. Also what will this look like when completed and printed?
Code:
System.Data.DataTable dt = (System.Data.DataTable)dataGrid.DataSource; |
Well, it depends on what exactly the dataGrid.DataSource is. You need to know that before you continue with this part of the code. Perhaps it is an entire dataset, which would mean you would have to change the code to something like this:
System.Data.DataTable dt = ((System.Data.DataSet)dataGrid.DataSource).Tables[0]; // or which ever table you need |
Ok, I am making progress, however I still cannot print. I have populated output but I now need to have a nice and neat printed document formatted with headers as well. How can this be done?
|
All times are GMT -5. The time now is 01:32 PM. |