We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Printing

Hi, I have DataBoundGrid which is bound to a table, but the grid does not display all the columns in the table. When the user selects print, I want to show and hide columns in the table in a different way. Some of the columns that are now visible should be hidden when printed and some should become visible. What is a good way to do this? Thanks!

5 Replies

Administrator October 19, 2004 04:50 AM UTC

Handle the QueryColWidth event. In the handler, if the grid is printing (check grid.PrintingMode), then set e.Size = 0 and e.Handled = true if e.Index points to one of the columns you want to hide.

MB Madhavi Balusu October 19, 2004 02:02 PM UTC

Yes, that would work for hiding the columns. What if I want to insert new columns into the grid during the printmode?

Administrator October 19, 2004 03:29 PM UTC

You want to print columns that are not visible in the grid when you are not printing? In such a case, it might be simpler to use a second grid to print things. That way you can hide / insert what ever you want and not affect the display. Another option is to handle the other virtual events, QueryCellInfo and QueryColCount and dynamically provide the values for the extra columns. This would be tricky. All in all, using a second grid might be the simplest thing to do.

MB Madhavi Balusu October 19, 2004 08:06 PM UTC

Hi Clay, In a databound grid, how do I get the DataTable (displayTable) of the grid with mapped values in the table not raw DB values? So if the table person cellvalue=4, I want the mapped display name like table cellvalue=John ( the mapped value from the db table ) Thanks.

Administrator October 19, 2004 08:35 PM UTC

I am not sure I understand. Are you asking how to get the Display value of a ComboBox cell that uses ValueMember and DisplayMember? If so, try retrieving the FormattedText. string displayValue = this.grid[row, col].FormattedText; If you want to get the DataRowView for for grid rowIndex, then you can use: CurrencyManager cm = (CurrencyManager) this.BindingContext[grid.DataSource,grid.DataMember]; int pos = grid.Binder.RowIndexToPosition(rowIndex); DataRowView drv = cm.List[pos] as DataRowView; string someValue = drv["anycolumn"].ToString();
Loader.
Live Chat Icon For mobile
Up arrow icon