Is there any inbuilt feature of xamgrid so that I can show rows count along with xamgrid whenever xamgrid gets loaded? I want to display total no. of rows (rows count=?) present in xamgrid.If there is no any inbuilt feature then help with code if possible..
There isn't anything in the XamGrid that is going to display the number of rows.
As long as you aren't delay loading your DataSource, you could look at the grid.Rows.Count and get how many rows you have (assuming flat datasource). By that measure you could look at the grid.ItemSource, cast it up from an IEnumerable to your list type and get it's .Count instead.
If your data is hiearchial, you would probably want to go through your object model to find out how much data is in it, rather then go through the grid for performance reasons.
If you just want row numbers then you can turn these on off the RowSelectorSettings object off the grid.
Darrell,
I am trying to do a similar thing; display the row count in the header of child grids in a hierarchical grid. You mention that a solution would be to "go through your object model to find out how much data is in it", but am not sure how to translate that to code.
If you were to take the hierarchical xamgrid example supplied by Infragistics in the demos as an example, how would I display a count of the number of Orders for each customer in the header of each Orders child grid? Can you provide the Xaml as an example please?
Thanks,
Andrew
Hi Andrew,
You could use the HeaderTemplate property of the column.
Then on your ViewModel you'd have a property for looking up the count, that you'd bind to.
The tricky part is the binding to the ViewModel, as you can only do StaticResource bindings in the HeaderTemplate. However, it's pretty easy to overcome.
1. Create a helper class
public class MyHelper{ public YourViewModel VM{get;set;}}
2. Add a StaticResource of this class in your UserControl's Resources:<local:MyHelper x:key="myVM" />
3. In the code behind get handle of the MyHelper class and set it's VM propertyMyHelper helper = this.Resources["myVM"] as MyHelper; if(helper != null) helper.VM = yourVM;
4. Now use this in your headerTemplate. <TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text={Binding Source={StaticResource myVM}, Path=VM.YourCountProprety/>
I hope that's enough to get you started.
-SteveZ
SteveZ,
I'm not sure how that would work. Could you please clarify how would I use your approach to implement the property on the viewmodel for "looking up the count"?
Can you supply an example - perhaps using the Heirarchial Data example (http://samples.infragistics.com/sllob/RunSamples.aspx?cn=grid#/grid/hierarchical-data) as a reference - how would I display a count of the number of Orders for each customer in the header of each Orders child grid (assuming that the header has been made visible)?
Hi,
I actually gave this some more thought, and my original suggestion really won't work, b/c you won't be able to get the context of what level you're on to pass to the ViewModel.
However, i think i thought of another way to approach this.
You'd need to re-template the HeaderCellControl for the column you'd like to display the count on.
Then you'd do add a TextBlock who's xaml would look like:
<TextBlock Text="{Binding Cell.Row.Manager.Rows.Count, RelativeSource={RelativeSource TemplatedParent} />
To get the original style of the HeaderCellControl, you can either use blend:
http://help.infragistics.com/NetAdvantage/Silverlight/2011/1/CLR4.0/?page=SL_DesignersGuide_Editing_Style_Properties_Using_Expression_Blend.html
Or the actual generic.xaml for the xamGrid: http://help.infragistics.com/NetAdvantage/Silverlight/2011/1/CLR4.0/?page=SL_DesignersGuide_Location_of_Generic_xaml_File.html
Once you've created your style, you can change the style of the header of a column via the HeaderStyle property on that column:
<ig:TextColumn Key="YourKey" HeaderStyle={StaticResource yourNewStyle}/>
I hop this is more helpful,