Hi,
I'm using grid.SelectedItems.Add(row); in a loop to select rows on a grid. However sometimes I need to select 10,000+ rows and this can take over 15 seconds. I have tired .AddRange() but that takes the same amount of time.
Is there a faster way to select items, especially with a very large number of rows?
Thanks,
Richard
Hello,
I don't get any rows displayed when filtering with popup mode, grouping with drag&drop and sorting either by clicking on the column header or programatically.
And I get all my rows back when clearing filter/grouping/sorting either directly on the UI or programatically. Could you please help me?
Designer.xaml
<
telerik:RadGridView
x:Name
=
"AttributesTable"
ItemsSource
=
"{Binding Path=Items}"
RowDetailsVisibilityMode
=
"Collapsed"
ScrollViewer.CanContentScroll
=
"False"
AutoGenerateColumns
=
"False"
CanUserSortColumns
=
"True"
Sorting
=
"AttributesTable_Sorting"
PreparedCellForEdit
=
"AttributesTable_PreparedCellForEdit"
CellEditEnded
=
"AttributesTable_CellEditEnded"
FilteringMode
=
"Popup"
IsFilteringAllowed
=
"True"
MouseLeftButtonDown
=
"AttributesTable_MouseLeftButtonDown"
FieldFilterEditorCreated
=
"OnRadGridViewFieldFilterEditorCreated"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
Button
Style
=
"{StaticResource NoChromeButton}"
Command
=
"{base:XamlRoot Path=DataContext.Navigate}"
CommandParameter
=
"{Binding}"
>
<
Image
Source
=
"/STTAR;component/Resources/Object_Globe_16xLG.png"
ToolTip
=
"{base:ResX ResKey=CenterMapToolTip}"
/>
</
Button
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
Code.cs
columns = (this.DataContext as AttributesTableViewModel)?.Columns;
items = (this.DataContext as AttributesTableViewModel)?.Items;
DynAdapter = (this.DataContext as AttributesTableViewModel)?.DynAdapter;
if (columns.Count == 0)
{
var temp = AttributesTable.Columns[0];
AttributesTable.Columns.Clear();
AttributesTable.Columns.Add(temp);
return;
}
var alreadyInsertedColsNames = (from col in (AttributesTable.Columns as ObservableCollection<
GridViewColumn
>).Where(col => col.DisplayIndex != 0) select col.Header as string).ToList();
var colsNames = (from col in columns select col.DisplayName).ToList();
var notInsertedColsNames = colsNames.Except(alreadyInsertedColsNames).ToList();
var toRemoveColsNames = alreadyInsertedColsNames.Except(colsNames).ToList();
if (notInsertedColsNames.Count > 0)
foreach (string colName in notInsertedColsNames)
{
FeatureAttribute selectedCol = columns.Where(col => col.DisplayName == colName).FirstOrDefault();
var gridViewColumn = new GridViewDataColumn();
switch (selectedCol.Name)
{
case FeatureAttributes.Cost:
string costUnit = String.Format(" ({0})", DynAdapter.Project.Settings.CurrencyCode);
gridViewColumn.Header = selectedCol.DisplayName + costUnit;
break;
case FeatureAttributes.Length:
string lengthUnit = " (m)";
gridViewColumn.Header = selectedCol.DisplayName + lengthUnit;
break;
case FeatureAttributes.Id:
case FeatureAttributes.Source:
case FeatureAttributes.Support:
gridViewColumn.IsReadOnly = true;
gridViewColumn.Header = selectedCol.DisplayName;
break;
default:
gridViewColumn.Header = selectedCol.DisplayName;
break;
}
// GetBindingStringForAttribute returns ".[propertyName]"
gridViewColumn.DataMemberBinding = new Binding(GetBindingStringForAttribute(selectedCol));
gridViewColumn.FilterMemberPath = GetBindingStringForAttribute(selectedCol);
gridViewColumn.FilterMemberType = selectedCol.DataType;
gridViewColumn.DataType = selectedCol.DataType;
gridViewColumn.ShowDistinctFilters = false;
gridViewColumn.CellTemplateSelector = (DataTemplateSelector)GridContainer.Resources["CellTemplateSelector"];
gridViewColumn.CellEditTemplateSelector = (DataTemplateSelector)GridContainer.Resources["CellEditTemplateSelector"];
AttributesTable.Columns.Add(gridViewColumn);
}
foreach (string toRem in toRemoveColsNames)
{
var colToRemove = (AttributesTable.Columns as ObservableCollection<
GridViewColumn
>)
.FirstOrDefault(col => col.Header == toRem);
if (AttributesTable.Columns.Contains(colToRemove))
AttributesTable.Columns.Remove(colToRemove);
}
We have our custom class for saving the grid configuration, i.e sorting/grouping/resizing/column order and we add Unloaded event on our grid like so:
public static void Persistence(/*params here*/)
grid.Unloaded += (sender, args) =>
{
var data = GenerateGridSettings(grid, whatToSave, column => column.UniqueName);
if (data != null)
// save settings goes here
};
}
Although this looks good and I as developer and the QA team do not get error messages, our customers get error messages, specifically "Object was not set to an instance of an object". The error output is this:
2020/09/03 09:36:17.259 29 - 17832 Client.Global.Dispatcher FATAL Object reference not set to an instance of an object.
at Controls.RadGridSupport.<>c.<Persistence>b__26_4(GridViewColumn column)
at Controls.RadGridSupport.GenerateGridSettings(RadGridView rgv, RadGridSettingSelection whatToSave, Func`2 mapColumnToName)
at Controls.RadGridSupport.<>c__DisplayClass26_0.<Persistence>b__1(Object sender, RoutedEventArgs args)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastUnloadedEvent(Object root)
at MS.Internal.LoadedOrUnloadedOperation.DoWork()
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
As if the column in the lambda expression "column => column.UniqueName" gets deleted at some point before unloaded event.
Is this possible? Can the column be deleted before the unloaded event?
I have a nested Dictionary with 5 levels.
I would like to show it in the TreeView but I only get the first layer.
<telerik:RadTreeView x:Name="myTreeView"
MinWidth="200px"
ItemsSource="{Binding Areas}"
ItemTemplate="{StaticResource BuildingHDT}"
ItemContainerStyle="{StaticResource ItemContainerStyle}"
MaxHeight="{Binding ElementName=host, Path=ActualHeight}"
Grid.IsSharedSizeScope="True"
HorizontalContentAlignment="Stretch"
IsVirtualizing="True"
TextSearch.TextPath="Value.Name"
extension:ContextMenuBehavior.ContextMenu="{Binding ElementName=TreeContextMenu}">
<telerik:RadContextMenu.ContextMenu>
<telerik:RadContextMenu x:Name="TreeContextMenu"/>
</telerik:RadContextMenu.ContextMenu>
<telerik:EventToCommandBehavior.EventBindings>
<telerik:EventBinding Command="{Binding OpenSelectedItem}"
EventName="MouseLeftButtonDown"
RaiseOnHandledEvents="True"
PassEventArgsToCommand="True" />
</telerik:EventToCommandBehavior.EventBindings>
</telerik:RadTreeView>
<HierarchicalDataTemplate x:Key="QualifierHDT"
DataType="{x:Type models:Qualifier}"
ItemsSource="{Binding Qualifier}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Value.Name}" />
<TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="ComponentHDT"
DataType="{x:Type models:Component}"
ItemsSource="{Binding Component}"
ItemTemplate="{StaticResource QualifierHDT}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Key}" />
<TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="SystemCollectionHDT"
DataType="{x:Type models:SystemCollection}"
ItemsSource="{Binding SystemCollection}"
ItemTemplate="{StaticResource ComponentHDT}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Value.Name}" />
<TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="BuildingHDT"
DataType="{x:Type models:Building}"
ItemsSource="{Binding Buildings}"
ItemTemplate="{StaticResource SystemCollectionHDT}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Value.Name}" />
<TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />
</StackPanel>
</HierarchicalDataTemplate>
When the user drags an item to the top or bottom of the TreeListView, I'd like to scroll automatically, to handle the case where the user wants to drag to an item that isn't currently in view. I have a small sample program I can provide you, and OnDragOver is shown below. Can you tell me how to detect that the drag has reached the top or bottom of the view and then scroll as needed?
Thanks,
Georg Hentsch
private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e) {
var dropTarget = e.OriginalSource as TreeListViewRow ?? (e.OriginalSource as FrameworkElement).ParentOfType<TreeListViewRow>();
var details = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails;
if (dropTarget == null || details == null) {
return;
}
details.CurrentDraggedOverItem = dropTarget.DataContext;
if (details.CurrentDraggedItem == details.CurrentDraggedOverItem) {
e.Effects = DragDropEffects.None;
e.Handled = true;
return;
}
details.CurrentDropPosition = GetDropPositionFromPoint(e.GetPosition(dropTarget), dropTarget);
if (IsChildOf(dropTarget, sourceItem)) {
e.Effects = DragDropEffects.None; // don't allow item to be dropped to one of its own children
}
e.Handled = true;
}
Dear Telerik Team,
I am using telerik Rad Grid View control and having issue with below code.
I am trying to set the background color of a row on mouse over.
Issue is On mouse over below Setter property 'Background' does not set the background color of the row instead it sets the border color. Pl advise on the correct Implementation.
<telerik:RadGridView x:Name="radGridView" Margin="8,100,0,0"
ItemsSource="{Binding Source={StaticResource AuthorsData}}"
IsFilteringAllowed="True"
AutoGenerateColumns="True" Grid.Column="1" >
<telerik:RadGridView.RowStyle>
<Style TargetType="telerik:GridViewRow">
<Setter Property="MinHeight" Value="20"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Green"/>
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
</telerik:RadGridView.RowStyle>
</telerik:RadGridView>
Thanks,
Vaibhav.
Hi
We have a radoutlookbar with some items in it When te user click on the minimize/restore-button ((1) in attached image) it works perfect, the bar and all it content moves out and in. (see attached image).
When user clicks on the "header" of the outlookbar ((2) in attached image) strange things happen. First click is most often than only the first user control in the first item slides out, after that, sometimes the entire outlookbar is stuck half minimized and we have to restart the application.
First of all, Im I doing something wrong in my xaml (below)?
If not, is there any setting where I can make the rest of the outlookbar to minimiza/restore or could I catch the event and programmatically restore it? (We are using te MVVM approach)
--xaml---------------------------------------
<telerik:RadOutlookBar DockPanel.Dock="Right" Width="600" IsVerticalResizerVisible="True" MinimizedButtonContent="Details" IsMinimized="True" >
<telerik:EventToCommandBehavior.EventBindings>
<telerik:EventBinding EventName="SelectionChanged" Command="{Binding DrawerItemChangedCommand}" PassEventArgsToCommand="True"/>
<telerik:EventBinding EventName="Restored" Command="{Binding ExpandCollapseDrawerCommand}" PassEventArgsToCommand="True"/>
<telerik:EventBinding EventName="Minimized" Command="{Binding ExpandCollapseDrawerCommand}" PassEventArgsToCommand="True"/>
</telerik:EventToCommandBehavior.EventBindings>
<modelview:OneView DataContext="{Binding OneViewModel}"/>
<telerik:RadOutlookBarItem Header="Another">
<modelview:AnotherView DataContext="{Binding AnotherViewModel}" />
</telerik:RadOutlookBarItem>
<telerik:RadOutlookBarItem Header="LastViewIPromise">
<moCompliance:LastView DataContext="{Binding LastViewModel}" />
</telerik:RadOutlookBarItem>
</telerik:RadOutlookBar>
-------------------------------------------------
Thanks in advance, Robert