This question is locked. New answers and comments are not allowed.
Hello Telerik Team,
I am using Silverilght 4 and Telerik File Version 2011.3.1116.1040.
My initial requirement was to make the Horizontal Scrollbar of the RadGridView scroll to the far right when the scrollbar is Visible, meaning that there would be Columns off screen. At first, I was simply doing the following which seemingly worked:
Until ... I soon discovered an issue where the RadGridView's Horizontal Scrollbar stays Visible even though it's set to Auto and all Columns are within view. This happens when the RadGridView's Width shrinks back down due to 2 other panes that are to the left of the RadGridView whose visibility gets toggled on and off by clicking their headers. The scrollbar would be present, but if you were to click once on the Vertical Scrollbar the Horizontal Scrollbar would disappear. This is obviously not what I want.
My attempt to solve the issue had me subscribing to the SizeChangedEventHandler. I would pass e.NewSize.Width to a method that would loop through the Columns aggregating each column's ActualWidth. If the Total Columns Width was greater than the New Grid Actual Width then we know that we need to show the Horizontal Scrollbar and scroll it to the far right via the code snippet above, otherwise we know that all Columns are within view so I can safely set the Horizontal Scrollbar to Hidden.
This, however, does work in all cases. When the SizeChangedEventHanlder is fired and the e.NewSize.Width is passed to my method, it seems to be the correct new width but, when I loop through the Columns, each Column retains its previous width, thus throwing off the calculation.
So the question becomes, "How do I a) get the New Actual Width for each Column or b) get the Horizontal Scrollbar to work correctly, as it should, when set to Auto?"
Here is my Method:
Here is my RadGridView XAML:
I am using Silverilght 4 and Telerik File Version 2011.3.1116.1040.
My initial requirement was to make the Horizontal Scrollbar of the RadGridView scroll to the far right when the scrollbar is Visible, meaning that there would be Columns off screen. At first, I was simply doing the following which seemingly worked:
this
.PaymentsGridView.ScrollIntoViewAsync
(
this
.PaymentsGridView.Items[0],
this
.PaymentsGridView.Columns[
this
.PaymentsGridView.Columns.Count - 1],
null
);
Until ... I soon discovered an issue where the RadGridView's Horizontal Scrollbar stays Visible even though it's set to Auto and all Columns are within view. This happens when the RadGridView's Width shrinks back down due to 2 other panes that are to the left of the RadGridView whose visibility gets toggled on and off by clicking their headers. The scrollbar would be present, but if you were to click once on the Vertical Scrollbar the Horizontal Scrollbar would disappear. This is obviously not what I want.
My attempt to solve the issue had me subscribing to the SizeChangedEventHandler. I would pass e.NewSize.Width to a method that would loop through the Columns aggregating each column's ActualWidth. If the Total Columns Width was greater than the New Grid Actual Width then we know that we need to show the Horizontal Scrollbar and scroll it to the far right via the code snippet above, otherwise we know that all Columns are within view so I can safely set the Horizontal Scrollbar to Hidden.
This, however, does work in all cases. When the SizeChangedEventHanlder is fired and the e.NewSize.Width is passed to my method, it seems to be the correct new width but, when I loop through the Columns, each Column retains its previous width, thus throwing off the calculation.
So the question becomes, "How do I a) get the New Actual Width for each Column or b) get the Horizontal Scrollbar to work correctly, as it should, when set to Auto?"
Here is my Method:
private
void
ScrollPaymentGridViewToTheFarRight(
double
gridWidth)
{
double
columnsWidth = 15.0;
// TODO: account for vertical scrollbar.
foreach
(
double
col
in
this
.PaymentsGridView.Columns)
columnsWidth += col.ActualWidth;
if
(columnsWidth > gridWidth)
{
ScrollViewer.SetHorizontalScrollBarVisibility(
this
.PaymentsGridView, ScrollBarVisibility.Auto);
this
.PaymentsGridView.ScrollIntoViewAsync
(
this
.PaymentsGridView.Items[0],
this
.PaymentsGridView.Columns[
this
.PaymentsGridView.Columns.Count - 1],
null
);
}
else
{
ScrollViewer.SetHorizontalScrollBarVisibility(
this
.PaymentsGridView, ScrollBarVisibility.Hidden);
}
}
}
Here is my RadGridView XAML:
<
telerik:RadGridView
x:Name
=
"PaymentsGridView"
GridLinesVisibility
=
"Vertical"
AlternationCount
=
"2"
AutoGenerateColumns
=
"False"
CanUserFreezeColumns
=
"False"
CanUserReorderColumns
=
"False"
CanUserSelect
=
"False"
CanUserSortColumns
=
"True"
Background
=
"DarkGray"
BorderBrush
=
"Transparent"
BorderThickness
=
"0"
Foreground
=
"Black"
IsReadOnly
=
"True"
IsFilteringAllowed
=
"True"
RowIndicatorVisibility
=
"Collapsed"
ScrollMode
=
"RealTime"
ShowColumnFooters
=
"True"
ShowGroupFooters
=
"False"
ShowGroupPanel
=
"False"
RowStyle
=
"{StaticResource rgvRowStyle}"
AlternateRowStyle
=
"{StaticResource rgvAlternateRowStyle}"
HeaderRowStyle
=
"{StaticResource rgvHeaderRowStyle}"
FooterRowStyle
=
"{StaticResource rgvFooterRowStyle}"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Status"
Footer
=
"Totals:"
DataMemberBinding
=
"{Binding Status}"
HeaderCellStyle
=
"{StaticResource rgvHeaderCellStyle}"
FooterCellStyle
=
"{StaticResource rgvFooterCellStyle}"
CellStyle
=
"{StaticResource rgvCellStyle}"
HeaderTextAlignment
=
"Left"
FooterTextAlignment
=
"Left"
TextAlignment
=
"Left"
Width
=
"Auto"
/>
<
telerik:GridViewDataColumn
Header
=
"Vendor #"
DataMemberBinding
=
"{Binding VendorNumber}"
HeaderCellStyle
=
"{StaticResource rgvHeaderCellStyle}"
FooterCellStyle
=
"{StaticResource rgvFooterCellStyle}"
CellStyle
=
"{StaticResource rgvCellStyle}"
HeaderTextAlignment
=
"Left"
TextAlignment
=
"Left"
Width
=
"Auto"
/>
<
telerik:GridViewDataColumn
Header
=
"Vendor Name"
DataMemberBinding
=
"{Binding VendorName}"
HeaderCellStyle
=
"{StaticResource rgvHeaderCellStyle}"
FooterCellStyle
=
"{StaticResource rgvFooterCellStyle}"
CellStyle
=
"{StaticResource rgvCellStyle}"
HeaderTextAlignment
=
"Left"
TextAlignment
=
"Left"
Width
=
"*"
MinWidth
=
"225"
/>
<
telerik:GridViewDataColumn
Header
=
"Input Date"
DataMemberBinding
=
"{Binding InputDateKey, Converter={StaticResource DateKeyConverter}}"
HeaderCellStyle
=
"{StaticResource rgvHeaderCellStyle}"
FooterCellStyle
=
"{StaticResource rgvFooterCellStyle}"
CellStyle
=
"{StaticResource rgvCellStyle}"
HeaderTextAlignment
=
"Left"
TextAlignment
=
"Left"
Width
=
"Auto"
/>
<
telerik:GridViewDataColumn
Header
=
"Period"
DataMemberBinding
=
"{Binding Period}"
HeaderCellStyle
=
"{StaticResource rgvHeaderCellStyle}"
FooterCellStyle
=
"{StaticResource rgvFooterCellStyle}"
CellStyle
=
"{StaticResource rgvCellStyle}"
HeaderTextAlignment
=
"Left"
TextAlignment
=
"Left"
Width
=
"Auto"
/>
<
telerik:GridViewDataColumn
Header
=
"Total Voucher"
DataMemberBinding
=
"{Binding TotalVoucherAmount, Converter={StaticResource Currency2Converter}}"
HeaderCellStyle
=
"{StaticResource rgvHeaderCellStyle}"
FooterCellStyle
=
"{StaticResource rgvFooterCellStyle}"
CellStyle
=
"{StaticResource rgvCellStyle}"
HeaderTextAlignment
=
"Right"
TextAlignment
=
"Right"
Width
=
"Auto"
>
<
telerik:GridViewColumn.AggregateFunctions
>
<
telerik:SumFunction
ResultFormatString
=
"{}{0:c}"
/>
</
telerik:GridViewColumn.AggregateFunctions
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Research"
DataMemberBinding
=
"{Binding ResearchAmount, Converter={StaticResource Currency2Converter}}"
HeaderCellStyle
=
"{StaticResource rgvHeaderCellStyle}"
FooterCellStyle
=
"{StaticResource rgvFooterCellStyle}"
CellStyle
=
"{StaticResource rgvCellStyle}"
HeaderTextAlignment
=
"Right"
TextAlignment
=
"Right"
Width
=
"Auto"
>
<
telerik:GridViewColumn.AggregateFunctions
>
<
telerik:SumFunction
ResultFormatString
=
"{}{0:c}"
/>
</
telerik:GridViewColumn.AggregateFunctions
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>