Hello,
I'm working on a XamDataGrid where I need to allow for rows to be added and displayed up to a max number of rows (then the scrollbar should appear and the grid stops expanding). For example: I have a grid with 3 rows displayed as the default. I want to allow the user to add rows and the grid expand to show the rows up to a max of 5 rows and then the grid stops expanding and the scroll bar kicks in. Initially, I set the xamdatagrid.height to auto, but I don't know how to turn this off after I reached the max number of rows. I tried setting the height to the "xamDataGrid.ActualHeight" after the max number of rows had been reached and it seemed to work. However, my custom grid navigation methods no longer worked in the grid (such as adding new rows by tabbing or hitting the down arrow). How do I turn the "auto" height off and keep the current height for the grid? Or is there a better way to do what I want to do here?
Thanks,
David
No there is no functionality in the control to provide the functionality mentioned in this post. You may submit a suggestion for adding it.
Hi I would like to know if there is something new in the new versions of the Grid to set the maximum number of rows.
Thank you
Can someone suggest how to get the actual amount of space above the XamDataGrid records?
The constant 32 works for some of my XamDataGrids (with headers with wrapped text), but with single line headers it's too much.
I did spend some time trying to walk the XamDataGrid control with VisualTreeHelper to see if I could find something useful, but there's a lot there and I got lost.
Mike
Thanks Alex - I was able to figure out a solution based on your suggestion.
Hello David,
There is not direct way of achieving this with the XamDataGrid but you can implement this fairly easy.
In the Loaded event of the XamDataGrid, get a random (first) DataRecordPresenter and see what's its height
void xamDataGrid1_Loaded(object sender, RoutedEventArgs e)
{
// Find the Height of one record and set the Height of the XamDataGrid according to it
DataRecordPresenter drp = DataRecordPresenter.FromRecord(xamDataGrid1.Records[0]) as DataRecordPresenter;
double height = drp.ActualHeight;
// Total Records : 7 (5 + 2)
// 5 Data Records + 2 Special Records (AddNewRecord and RecordFiltering)
// 32 - Spaces above the records of the XamDataGrid ( this may vary )
(sender as XamDataGrid).Height = drp.ActualHeight * 7 + 32;
}