Home Forums WPF controls Xceed DataGrid for WPF Printing too many columns

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24434 |

    Hello,

    I found an issue with the printing that I couldn’t seem to find a work around for yet. I was wondering if someone could point me in the right direction?

    I have a datagrid bound to a source that could display up to 10 columns. However, I only want to display 7 of those. I declare which columns I want to display using the following code:

    <xcdg:DataGridControl AutoCreateColumns=”False” …>

    <xcdg:DataGridControl.Columns>
    <xcdg:Column … />
    <xcdg:Column … />

    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    This allows me choose which columns display at run time. However, when I print, it will first print my column collection then it will tack on the rest of the columns I did not specify in my markup.

    In the print sample you can set AutoCreateColumns=False and comment out a few of the columns to reproduce the behavior.

    Is there a way to specify which columns get printed?

    Imported from legacy forums. Posted by Jason (had 594 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Jason,

    There does seem to be an issue with printing and AutoCreateColumns, which has been noted. However, AutoCreateColumns should rarely, if ever, be used. Instead, you should be using the DataGridCollectionViewSource and limiting the columns using the ItemProperties. Doing so will result in only those columns being printed.

    <code>
    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid”&gt;
    <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”cvs_orders”
    Source=”{Binding Source={x:Static Application.Current},
    Path=Orders}”>
    <xcdg:DataGridCollectionViewSource.ItemProperties>
    <xcdg:DataGridItemProperty Name=”ShipCountry”/>
    <xcdg:DataGridItemProperty Name=”ShipCity”/>
    </xcdg:DataGridCollectionViewSource.ItemProperties>
    </xcdg:DataGridCollectionViewSource>
    </Grid.Resources>
    <DockPanel>
    <Button Content=”Print Grid”
    Click=”PrintGrid”
    DockPanel.Dock=”Top”/>

    <xcdg:DataGridControl x:Name=”OrdersGrid”
    ItemsSource=”{Binding Source={StaticResource cvs_orders}}”>
    <xcdg:DataGridControl.PrintView>
    <xcdg:PrintTableView>
    <xcdg:PrintTableView.PageHeaders>
    <DataTemplate>
    <TextBlock Text=”Xceed WPF Documentation”
    HorizontalAlignment=”Center”
    FontWeight=”Bold”
    FontSize=”20″/>
    </DataTemplate>
    <DataTemplate>
    <TextBlock Text=”Printing Example”
    HorizontalAlignment=”Center”
    FontSize=”16″/>
    </DataTemplate>
    </xcdg:PrintTableView.PageHeaders>
    <xcdg:PrintTableView.PageFooters>
    <DataTemplate>
    <TextBlock Text=”{xcdg:ViewBinding CurrentPageNumber}”
    HorizontalAlignment=”Right”/>
    </DataTemplate>
    </xcdg:PrintTableView.PageFooters>
    </xcdg:PrintTableView>
    </xcdg:DataGridControl.PrintView>

    </xcdg:DataGridControl>
    </DockPanel>
    </Grid>

    </code>

    Imported from legacy forums. Posted by Jenny [Xceed] (had 378 views)

    User (Old forums)
    Member
    Post count: 23064

    <em>”However, AutoCreateColumns should rarely, if ever, be used.”</em>

    Um, why is that? Having to use the DataGridCollectionViewSource is a violation of The Principle of Least Surprise. Not to mention a proliferation of markup.

    Imported from legacy forums. Posted by bennage (had 271 views)

    User (Old forums)
    Member
    Post count: 23064

    Check out the FAQ, #2:
    http://forums.xceed.com/forums/ShowPost.aspx?PostID=6869

    The DataGridCollectionViewSource is causing some other problems for me. Hopefully, I’ll find a resolution and post it…

    Imported from legacy forums. Posted by bennage (had 3938 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.