Dears,
i am not setting the width of the pivotgrid because i want it to take the size of the web page,
but how to set the numbers of columns viewed to exactly 12, and the user can scroll, but i want him to c only 12 at a time.
how can i do that?
Thanks,
Hi
You can set columns width. First you should find the width of columns panel and divide it to 12 to find the one column width and then set it to column See snippet below.
void PivotGridContainer_Loaded(object sender, RoutedEventArgs e) { PivotColumnsPanel obj = GetObject(PGrid, "ColumnsHeaderPanel") as PivotColumnsPanel; double columnWidth = obj.RenderSize.Width / 12; for (int index = 0; index < 12; index++) { PGrid.DataColumns[index].ColumnWidth = columnWidth; } } private DependencyObject GetObject(DependencyObject obj, string name) { DependencyObject child = null; int coutn = VisualTreeHelper.GetChildrenCount(obj); for (int index = 0; index < coutn; index++) { child = VisualTreeHelper.GetChild(obj, index); if (child is FrameworkElement && (child as FrameworkElement).Name == name) { return child; } child = GetObject(child, name); if (child != null) { return child; } } return child; }
Todor
I tried to call the function PivotGridContainer_Loaded from
this.Loaded += PivotGridContainer_Loaded; which is in the mainpage function and after initialize components and after giving the grid the datasouce
when i debug, the gird is not null while the PivotColumnsPanel obj is null
Hi,
It still gives me null value
this.pivotGrid.Loaded += new RoutedEventHandler(PivotGridContainer_Loaded);
because the int coutn = VisualTreeHelper.GetChildrenCount(obj);
count is always zero and child = VisualTreeHelper.GetChild(obj, index); is null
What is the type of the 'obj'. You should give the pivotGrid.
void PivotGridContainer_Loaded(object sender, RoutedEventArgs e) { PivotColumnsPanel obj = GetObject(this.pivotGrid, "ColumnsHeaderPanel") as PivotColumnsPanel; double columnWidth = obj.RenderSize.Width / 12; for (int index = 0; index < 12; index++) { pivotGrid.DataColumns[index].ColumnWidth = columnWidth; } ScrollBar vert = GetObject(pivotGrid, "VerticalScrollBar") as ScrollBar; ScrollBar horiz = GetObject(pivotGrid, "HorizontalScrollBar") as ScrollBar; }
so in my case the object is PivotColumnsPanel andScrollBar.
i tried to call this function PivotGridContainer_Loaded from the pivotGrid_CellControlAttached and it worked, the object returned a value, but i dont want it to be called for each cell, i want it for the whole grid.
It seems that you havent set the datasource when the Loaded event is fired and the panels and scroll bars are not visible. So that is why VisualTreeHelper can not find them.
In this case you can use LayoutLoaded event ot get your visual elements
this.piotGrid.LayoutLoaded += new System.EventHandler<System.EventArgs>(PGrid_LayoutLoaded);
I have put it like that
public MainPage() { InitializeComponent(); ObservableCollection<Sale> mSharesData = SampleDataGenerator.GenerateSales(500); ((FlatDataSource)this.pivotGrid.DataSource).ItemsSource = mSharesData;
this.pivotGrid.DataSource.ResultChanged += (sender, e) => { Update(); };
}
any way, if i put it in the update function, it works :)