C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to load large set of rows and columns in wpf grid?


Posted Date: 06 Aug 2008      Total Responses: 1

Posted By: Praveen Chandran       Member Level: Silver     Points: 1


Hi experts,

I want to know, how to load large grid in wpf?.
I have a grid having a maximum of 64000 rows and 5000 columns. In each cell of the grid, i have to load one rectangle and one path (Symbol). But when i load this large grid, wpf cant load this. The system is hanging.

Any idea for loading such a large grid in wpf??

Thanks in advance




Responses

Author: Vidhya    09 Aug 2008Member Level: GoldRating:     Points: 6
hi,

If you want to display a large number of rows in a grid you will definitely need a scroll feature in your grid but does the grid control in WPF has this feature? The answer is pretty straight, NO.



Hmm, then how I am supposed to display 100 records in a grid? Well the first answer to that is just use the ScrollViewer control around the grid. That would be a short time solution, once run your app you will come to agreement that is not really what you want. You will notice that the header part of the grid will get included in the ScrollViewer as well, which is not very pleasant to the user basically when the user scrolls down, the header gets disappear.



Is there any other solution? Yes, there is a nicer way. It is just not very obvious at first but you will get used to that after using it for couple times. Here are the steps: First of all you need to have two grids one for the header and the other one for the main body. The main grid will be in the ScrollViewer control as you would also guess. So this will solve the problem, very simple!!!



<Grid Name="grid1" TextBlock.Foreground="Chocolate">

<Grid.Resources>

<Style TargetType="{x:Type Border}">

<Setter Property="BorderThickness" Value="1" />

<Setter Property="Background" Value="AntiqueWhite" />

<Setter Property="BorderBrush" Value="Gray" />

</Style>

</Grid.Resources>

<Grid.ColumnDefinitions>

<ColumnDefinition Width="0.2*"/>

<ColumnDefinition Width="0.2*"/>

<ColumnDefinition Width="0.2*"/>

<ColumnDefinition Width="0.2*"/>

</Grid.ColumnDefinitions>

<Border Grid.Column="0" >

<TextBlock>Role</TextBlock>

</Border>

<Border Grid.Column="1" >

<TextBlock>Name</TextBlock>

</Border>

<Border Grid.Column="2" >

<TextBlock>Start Date</TextBlock>

</Border>

<Border Grid.Column="3" >

<TextBlock>End Date</TextBlock>

</Border>

</Grid>

<ScrollViewer Height="100" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" >

<Grid Name="grid2" >

<Grid.ColumnDefinitions>

<ColumnDefinition Width="0.08*"/>

<ColumnDefinition Width="0.1*"/>

<ColumnDefinition Width="0.14*"/>

<ColumnDefinition Width="0.14*"/>

</Grid.ColumnDefinitions>

<Grid.RowDefinitions>

<RowDefinition Height="0.2*" />

<RowDefinition Height="0.2*" />

</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Grid.Column="0">Role1</TextBlock>

<TextBlock Grid.Row="0" Grid.Column="1">

<Hyperlink NavigateUri="Page1.xaml">Name1</Hyperlink>

</TextBlock>

<TextBlock Grid.Row="0" Grid.Column="2">01/01/2006</TextBlock>

<TextBlock Grid.Row="0" Grid.Column="3">01/01/2007</TextBlock>

<TextBlock Grid.Row="1" Grid.Column="0">Role2</TextBlock>

<TextBlock Grid.Row="1" Grid.Column="1">

<Hyperlink NavigateUri="Page2.xaml">Name2</Hyperlink>

</TextBlock>

<TextBlock Grid.Row="1" Grid.Column="2">01/01/2007</TextBlock>

<TextBlock Grid.Row="1" Grid.Column="3">01/01/2008</TextBlock>

</Grid>

</ScrollViewer>



But now there is another issue that is the size of the header columns doesn’t match the size of the main grid columns. To fix this you just need to simply use this grid property SharedSizeGroup. Set this property on every column on the header grid to the unique name and then set the use the same names to set this property on the main grid columns. That simple!!!



<Grid.ColumnDefinitions>

<ColumnDefinition Width="0.08*" SharedSizeGroup="Role"/>

<ColumnDefinition Width="0.1*" SharedSizeGroup="Name"/>

<ColumnDefinition Width="0.14*" SharedSizeGroup="StartDate"/>

<ColumnDefinition Width="0.14*" SharedSizeGroup="EndDate"/>

</Grid.ColumnDefinitions>



One last thing that you will notice is that the size of the last column on the header does not match the last column on the main grid. Hmm, now you need to this last trick to fix this issue. First you need to add one more ColumnDefinition to your header grid by setting its width to Auto:



<ColumnDefinition Width="Auto" />



Then add this item to be the last column in the header grid and set the width to this DynamicResource.



<FrameworkElement Grid.Column="4" Width="{DynamicResource {x:Static SystemParameters.ScrollWidthKey}}" />




Post Reply
You must Sign In to post a response.
Next : drag and drop a wpf tree view
Previous : How to remove grip and overflowmenu from Toolbar control in WPF
Return to Discussion Forum
Post New Message
Category: WPF

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

Help Desk

Contact Us    Privacy Policy    Terms Of Use