Telerik Forums
UI for WPF Forum
1 answer
270 views

Hi,

I use the RadGridView with a VQCV and dynamic typed data in it. This works fine so far. My problem is, that I want to select the first row after the first set of data was loaded. I get the ItemsLoaded event and set the a SelectedItem property in my ViewModel. This property is bound to the RadGridView but it doesn't render the selected item correct (yellow selection). If I selected rows using the mouse everything works fine, only the programatic selection doesn't work.

I have debugged the issue for a while and wonder that I can see, that the RadGridView has the correct object referenced by the SelectedItem property, but visually the row is not selected.

public class MainWindowViewModel : INotifyPropertyChanged
    {
        private DynamicDataRow selectedItem;
 
        public MainWindowViewModel()
        {
            this.Data = new VirtualQueryableCollectionView { LoadSize = 10, VirtualItemCount = 1000 };
            this.Data.ItemsLoading += this.ViewItemsLoading;
            this.Data.ItemsLoaded += this.ViewItemsLoaded;
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        public VirtualQueryableCollectionView Data { get; private set; }
 
        public DynamicDataRow SelectedItem
        {
            get
            {
                return this.selectedItem;
            }
            set
            {
                this.selectedItem = value;
                this.OnPropertyChanged();
            }
        }
 
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
 
        private static void GenerateData(List<dynamic> data, int startIndex = 0)
        {
            var random = new Random(1000);
 
            for (int i = startIndex; i < startIndex + 10; i++)
            {
                var row = new DynamicDataRow();
 
                row.Add("Time", DateTime.Now);
                row.Add("NameD", "Klaus" + i);
                row.Add("Age", Convert.ToInt16(random.Next(short.MaxValue)));
                row.Add("Null", (object)null);
                row.Add("Double", Convert.ToDouble(1.3434));
 
                data.Add(row);
            }
        }
 
        private void ViewItemsLoaded(object sender, VirtualQueryableCollectionViewItemsLoadedEventArgs e)
        {
            if (e.StartIndex == 10)
            {
                foreach (DynamicDataRow item in e.Items)
                {
                    this.SelectedItem = item;
                    break;
                }
            }
        }
 
        private void ViewItemsLoading(object sender, VirtualQueryableCollectionViewItemsLoadingEventArgs e)
        {
            var source = sender as VirtualQueryableCollectionView;
 
            if (source == null)
            {
                return;
            }
 
            var data = new List<dynamic>();
            GenerateData(data, e.StartIndex);
            source.Load(e.StartIndex, data);
        }
    }

/// <summary>
    ///     A collection of dynamic data rows can be used to populate a RadGridView
    ///     with content if the number of columns is variable and only known during
    ///     runtime.
    /// </summary>
    /// <seealso cref="System.Dynamic.DynamicObject" />
    public class DynamicDataRow : DynamicObject
    {
        private readonly IDictionary<string, object> data;
 
        /// <summary>
        ///     Initializes a new instance of the <see cref="DynamicDataRow" /> class.
        /// </summary>
        public DynamicDataRow()
        {
            this.data = new Dictionary<string, object>();
        }
 
        /// <summary>
        ///     Adds a value to a specified column in the current row.
        /// </summary>
        /// <param name="columnName">The column name.</param>
        /// <param name="value">The value for the cell.</param>
        public void Add(string columnName, object value)
        {
            this.data[columnName] = value;
        }
 
        /// <summary>
        ///     Call this method to get a list of all column names. The method
        ///     is used by the RadGridView to generate the columns during runtime-
        /// </summary>
        /// <returns>
        ///     A sequence that contains the column names.
        /// </returns>
        public override IEnumerable<string> GetDynamicMemberNames()
        {
            return this.data.Keys;
        }
 
        /// <summary>
        ///     Provides the implementation for operations that get member values. Classes derived from
        ///     the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify
        ///     dynamic behavior for operations such as getting a value for a property.
        /// </summary>
        /// <param name="binder">
        ///     Provides information about the object that called the dynamic operation.
        ///     The binder.Name property provides the name of the member on which the dynamic operation is
        ///     performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement,
        ///     where sampleObject is an instance of the class derived from the
        ///     <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleProperty".
        ///     The binder.IgnoreCase property specifies whether the member name is case-sensitive.
        /// </param>
        /// <param name="result">
        ///     The result of the get operation. For example, if the method is called
        ///     for a property, you can assign the property value to <paramref name="result" />.
        /// </param>
        /// <returns>
        ///     True if the operation is successful; otherwise, false. If this method returns false, the
        ///     run-time binder of the language determines the behavior. (In most cases, a run-time
        ///     exception is thrown.)
        /// </returns>
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = this.data[binder.Name];
            return true;
        }
 
        /// <summary>
        ///     Provides the implementation for operations that set member values. Classes derived
        ///     from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method
        ///     to specify dynamic behavior for operations such as setting a value for a property.
        /// </summary>
        /// <param name="binder">
        ///     Provides information about the object that called the dynamic
        ///     operation. The binder.Name property provides the name of the member to which the value
        ///     is being assigned. For example, for the statement sampleObject.SampleProperty = "Test",
        ///     where sampleObject is an instance of the class derived from the
        ///     <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleProperty".
        ///     The binder.IgnoreCase property specifies whether the member name is case-sensitive.
        /// </param>
        /// <param name="value">
        ///     The value to set to the member. For example, for
        ///     sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class
        ///     derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, the
        ///     <paramref name="value" /> is "Test".
        /// </param>
        /// <returns>
        ///     True if the operation is successful; otherwise, false. If this method returns false,
        ///     the run-time binder of the language determines the behavior. (In most cases, a
        ///     language-specific run-time exception is thrown.)
        /// </returns>
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            this.data[binder.Name] = value;
            return true;
        }
    }
<Window x:Class="WPF.RadGridViewVirtualizing.MainWindow"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"       
        xmlns:controls="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <controls:RadGridView CanUserReorderColumns="False"
                                 ShowGroupPanel="False"
                                 AutoGenerateColumns="True"                                
                                 Grid.Row="0"
                                 IsFilteringAllowed="False"
                                 IsReadOnly="True"
                                 GridLinesVisibility="Both"
                                 SelectionMode="Extended"
                                 SelectionUnit="FullRow"                                
                                 RowIndicatorVisibility="Collapsed"                                
                                 AlternationCount="2"
                                 AlternateRowBackground="#F2F2F2"
                                 ItemsSource="{Binding Data}"
                                 SelectedItem="{Binding SelectedItem}"
                                 CanUserFreezeColumns="False"/>                   
    </Grid>
</Window>

I tried to attach a small project which reproduces the problem, but zip was not allowed :(

Thanks

Michael

Stefan
Telerik team
 answered on 27 May 2016
5 answers
149 views
Hi,

how can I prevent a childgridview from horizontal scrolling (the first two Columns)? I´d set the FrozenColumnCount-Property to 2 but it don´t worked, the entire childgridview is scrolling.

Bye, Michael
David
Top achievements
Rank 1
 answered on 26 May 2016
4 answers
176 views

Hello,

I have a master GridView and a details GridView in a RowDetailsTemplate. The master GridView is set to use FrozenColumnCount and works when the master GridView is scrolled horizontally as I expected, meaning the specified columns do not scroll.

The detail GridView is also set to use FrozenColumnCount. But when I scroll at the master GridView level, the frozen columns in the detail GridView scroll anyway.

Is there a way to scroll at the master GridView level, and have the detail GridView respect the FrozenColumnCount setting?

Any suggestions?

Thanks in advance!

Scott

Scott
Top achievements
Rank 1
 answered on 26 May 2016
1 answer
82 views

Hello,

I've tried every possible value for FooterTextAlignment, but the text is always right aligned.

It seems that it is not working

Dilyan Traykov
Telerik team
 answered on 26 May 2016
2 answers
346 views

Hi, I was posting here as well because I can't manage to get custom properties of Telerik WPF controls in Coded UI tests. I am working with the latest version of UI for WPF.

According to the information given here, most of the controls have support for Coded UI tests on level 2 and 3. That would mean that it is possible to get the value of custom properties during a Coded UI test.

In order to do this, I installed the UITest extension dll according to the instructions. I am working with Visual Studio 2015, so I placed the dll into the "%CommonProgramFiles(x86)%\Microsoft Shared\VSTT\14.0\UITestExtensionPackages" folder and stored it into the GAC as well.

Now I am able to use Telerik UI control classes in my test. The test runs fine as long as I don't work with any custom properties. If I open the Coded UI test builder (which I normally don't use for writing tests), I can pull the crosshair over a Telerik control like a RadButton and the test builder will show me its custom properties with value (i.e. IsBackgroundVisible for RadButton).

However, if I try getting the same property from within my test, it fails with the exception:

"System.NotSupportedException: GetProperty of "IsBackgroundVisible" is not supported on control type: Button"

The MainWindow XAML code of an example application:

<Window x:Class="TelerikCustomPropertiesApp.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                Title="MainWindow" Height="350" Width="525"
                AutomationProperties.AutomationId="Window_Test">
    <Grid>
        <telerik:RadButton
                Width="120"
                Height="35"
                AutomationProperties.AutomationId="Button_Test"
                Content="Test" />
    </Grid>
</Window>

My test code:

ApplicationUnderTest.Launch(@"..\TelerikCustomPropertiesApp.exe");
WpfWindow mainWindow = new WpfWindow();
mainWindow.SearchProperties[WpfControl.PropertyNames.AutomationId] = "Window_Test";
mainWindow.Find();
WpfRadButton button = new WpfRadButton(mainWindow);
button.SearchProperties[WpfControl.PropertyNames.AutomationId] = "Button_Test";
button.DrawHighlight();
// from here the test fails
bool test = button.IsBackgroundVisible;

Having a look at this MSDN article, can it be that there is no implementation of GetPropertyNames() in the PropertyProvider of the UITest extension. Or there is a problem with identifying the control type. Am I missing something important in order to make this work?

Daniel
Top achievements
Rank 1
 answered on 26 May 2016
2 answers
330 views

Hello, can someone tell me how to style a RadTreeViewItem purely in code behind?

I did read this article: http://docs.telerik.com/devtools/wpf/controls/radtreeview/styles-and-templates/styling-and-appearance-styling-radtreeviewitem#modifying-the-default-style

but I don't want to use XAML at all and I don't know how to access those properties in code.

Greg
Top achievements
Rank 1
 answered on 26 May 2016
10 answers
488 views

Hello, 

 

In my RadRibbonGroup, I want to hide his icon, but I don't find which property use.

To problem-round bypasses, I set Icon property with a small .png file without background, but the icon in RadRibbonGroup is so ugly... (file "1").

 

 

Have you got any idea ?

 

Thank you.

 

Valentin.

Valentin
Top achievements
Rank 2
Iron
Iron
Iron
 answered on 26 May 2016
1 answer
298 views

Hi team,

i am usng radImage Editor and trying to load jpg image in via ImageFormatProviderManager.import function and getting error that {"The image cannot be decoded. The image header might be corrupted."}.

 

Same image i can load in image editor demo wpf application given by telerik.

 

I want to know the reason

 

code here 

 string extension = Path.GetExtension(resource).ToLower();

            IImageFormatProvider formatProvider = ImageFormatProviderManager.GetFormatProviderByExtension(extension);
            //Image image = Image.FromFile(resource);
            MemoryStream mmStream = new MemoryStream();

            using (FileStream fsStream = File.OpenRead(resource))
            {
                fsStream.CopyTo(mmStream);
            }
            return formatProvider.Import(mmStream);

 

Also attached the exception screen shot and sample Jpg file

 

Regards

Hema

 

Todor
Telerik team
 answered on 26 May 2016
6 answers
1.6K+ views

I've been trying to change the size of the calendar in the DateTimePicker. Most likely a larger font size of the calendar is what's needed.

I tried following the following link, but could not get the theme to work.  http://www.telerik.com/forums/how-to-easily-change-font-size

Any help is appreciated.

Thanks...

Jace
Top achievements
Rank 1
 answered on 25 May 2016
2 answers
162 views

Is it possible to make the clock portion as one column with a vertical scrollbar?  Attached is a pic of kind of what I'm looking for.

Thanks...

Jace
Top achievements
Rank 1
 answered on 25 May 2016
Narrow your results
Selected tags
Tags
GridView
General Discussions
Chart
RichTextBox
Docking
ScheduleView
ChartView
TreeView
Diagram
Map
ComboBox
TreeListView
Window
RibbonView and RibbonWindow
PropertyGrid
DragAndDrop
TabControl
TileView
Carousel
DataForm
PDFViewer
MaskedInput (Numeric, DateTime, Text, Currency)
AutoCompleteBox
DatePicker
Buttons
ListBox
GanttView
PivotGrid
Spreadsheet
Gauges
NumericUpDown
PanelBar
DateTimePicker
DataFilter
Menu
ContextMenu
TimeLine
Calendar
Installer and Visual Studio Extensions
ImageEditor
BusyIndicator
Expander
Slider
TileList
PersistenceFramework
DataPager
Styling
TimeBar
OutlookBar
TransitionControl
FileDialogs
Book
ToolBar
ColorPicker
TimePicker
MultiColumnComboBox
SyntaxEditor
VirtualGrid
Wizard
ExpressionEditor
NavigationView (Hamburger Menu)
WatermarkTextBox
DesktopAlert
BarCode
SpellChecker
DataServiceDataSource
EntityFrameworkDataSource
RadialMenu
ChartView3D
Data Virtualization
BreadCrumb
LayoutControl
ProgressBar
Sparkline
TabbedWindow
ToolTip
CloudUpload
ColorEditor
TreeMap and PivotMap
EntityFrameworkCoreDataSource (.Net Core)
HeatMap
Chat (Conversational UI)
VirtualizingWrapPanel
Calculator
NotifyIcon
TaskBoard
TimeSpanPicker
BulletGraph
Licensing
WebCam
CardView
DataBar
FilePathPicker
PasswordBox
SplashScreen
Callout
Rating
Accessibility
CollectionNavigator
Localization
AutoSuggestBox
Security
VirtualKeyboard
HighlightTextBlock
TouchManager
StepProgressBar
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?