Telerik Forums
UI for WPF Forum
2 answers
193 views
I am trying to implement row-level validation when using the RadGridView bound to a DataView. The xaml looks like this:

<telerik:RadGridView Grid.Column="1" Grid.Row="1" Name="_gridTableGrid" ItemsSource="{Binding TableDataView, Mode=TwoWay}" />

The TableDataView property is a DataView from a DataSet into which I have read a series of records, e.g.,

TableDataView = myDataSet.Tables[0].DefaultView;

I subscribe to the following events:

myDataSet.Tables[0].RowChanging += new DataRowChangeEventHandler(DataTable_RowChanging);
myDataSet.Tables[0].RowChanged += new DataRowChangeEventHandler(DataTable_RowChanged);

I am using row-level validation because the row change may be rejected by the DBMS when I go to update the backing store. With other grids, the validation can be done before the focus leaves the current row and signaling a validation failure prevents the user from leaving that row without either correcting the error or rolling the change back. I am trying to use the e.Row.RowError property that I recieve in the DataRowChangeEventArgs e argument passed to my event handlers. That does not seem to have the effect that I am looking for: specifically, the row header should show an error and the user is restricted from leaving the record until the issue is addressed.

Any suggestions on how this would be handled from my view-model/model? Maybe the change in error status needs to be propagated back to the grid in some fashion other than this because this has no effect. If I work through cell-level validation, I get results that one would expect. But, cell-level validation is not useful in this condition.

Edit: By the way, if you try to use e.Row.RejectChanges() in the DataTable_RowChanging event handler, you'll get an error that says that you should throw an exception to cancel the row operation. If I throw an InvalidOperationException, for example, it is caught by my unhandled exception handler. I think that is the Microsoft method - the exception will be caught by the grid control and the message displayed. So, no joy in that direction, either.

Edit 2: Ok, so we don't handle it from our (view-)model, we go out to the code behind. Change the xaml to include RowValidating="OnRowValidating" and  RowValidated="OnRowValidated" and add those handlers. In a stub OnRowValidating
handler, write:

private void OnRowValidating(object sender, Telerik.Windows.Controls.GridViewRowValidatingEventArgs e)
{
    e.IsValid = false;
    e.ValidationResults.Add(new Telerik.Windows.Controls.GridViewCellValidationResult() {ErrorMessage = "byte me!"} );
}

Now we get the expected behavior: it will flag the record in the header and the tool tip 'byte me!' is shown on mouse over. This brings up another problem - the cancel behavior. As expected, the first escape cancels the edit on the current cell (really the last cell with the focus before the validation event). The second escape reverts the record. Almost. Here's what happens: if the first cell contained the value '5' and it was changed to '55' before the commit, the '55' is left in that field after the cancel. So the user now sees his incorrect value(s) in the grid after he performed the escape sequence.

The frustration with this behavior is quite high. We're so close in getting the correct behavior from the view-model. Why didn't Telerik just allow the exception ala MS to signal the validation error? And, when I use what appears to be the Telerik method, it fails in the rollback. I am using the last Q2 release because my attempt to move to the Q3 found a lack of fixes for what I currently have in the Q2 code and new errors introduced in the Q3 release.
Tsvyatko
Telerik team
 answered on 16 Dec 2011
0 answers
118 views
Hi,

I have a collection of simple objects ('Docks') that have a Name property which is a string. In a RadGridView I have a column defined as follows:

<telerik:GridViewComboBoxColumn Header="Dock"
                DisplayMemberPath="Name"
                SelectedValueMemberPath="Name"
                DataMemberBinding="{Binding DockName}"
                ItemsSource="{Binding Source={StaticResource LocatorKeeper}, Path=Locator.DocksDataViewModel.DocksCollection}" />

This correctly allows me to choose from entered Docks and assign it to a property of the element from the itemssource of the grid.

If I go back to the grid that is bound to the collection with Docks, I can update the name of a Dock. When I go back to the grid with the combobox column, I now correctly see the name updated in the combobox. However, the underlying object still has the old name saved. What I expect would happen is that the value is also written through the binding and stored in the DockName property of the object.

The current behavior is very misleading since the GUI shows the change to be propagated through the application whereas this is not actually the case.  I would like to know if there is a solution or a workaround for this issue.

Update (19-12-2011): after doing some further thinking it occurred to me that it is bad design to have your dependencies enforced by the presentation layer. The best solution is to simply store a reference to the object that contains the Name, so the type of  'DockName' should be changed from string to DockType and the SelectedValueMemberPath should be removed. After that it works as it should.

Of course, it remains the case the the behavior of the RadComboBox is misleading and it would be better to show a blank instead of the changed value.
Steven
Top achievements
Rank 1
 asked on 16 Dec 2011
1 answer
138 views
Dear Support!

I am using RadControls_for_WPF_2011_3_1205_DEV_hotfix.

When I am using RadGridView with VirtualQueryableCollectionView and I am pressing PageDown it's sometimes not working.
Every third keypress is not working (refer attachment).

Please let me know how to resolve the issue.

MainWindow.xaml
<Window x:Class="VirtualQueryableCollectionViewBugDemo.MainWindow"
        Title="MainWindow" Height="510" Width="700">
    <DockPanel>
        <TextBlock Width="250" Text="{Binding Log}" />
        <telerik:RadGridView ItemsSource="{Binding VirtualQueryableCollectionView}" EnableRowVirtualization="True" />
    </DockPanel>
</Window>


MainWindow.xaml.cs
namespace VirtualQueryableCollectionViewBugDemo
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            this.DataContext = new MainViewModel();
        }
    }
}


MainViewModel.cs
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using Telerik.Windows.Data;
 
namespace VirtualQueryableCollectionViewBugDemo
{
    public class MainViewModel : INotifyPropertyChanged
    {
        public VirtualQueryableCollectionView VirtualQueryableCollectionView { get; set; }
        private ObservableCollection<Row> items { get; set; }
 
        public MainViewModel()
        {
            this.items = new ObservableCollection<Row>(Generator.GenerateTestData());
             
            this.VirtualQueryableCollectionView = new VirtualQueryableCollectionView(this.items);
            this.VirtualQueryableCollectionView.LoadSize = 20;
            this.VirtualQueryableCollectionView.ItemsLoading += (s, e) =>
            {
                AppendLog(string.Format("Load StartIndex={0} ItemsCount={1}", e.StartIndex, e.ItemCount));
                this.VirtualQueryableCollectionView.Load(e.StartIndex,
                    this.items.Cast<Row>().Skip(e.StartIndex).Take(e.ItemCount));
            };
        }
 
        private string log;
        public string Log
        {
            get { return this.log; }
            set
            {
                this.log = value;
                RaisePropertyChanged("Log");
            }
        }
        public void AppendLog(string message)
        {
            this.Log = message + Environment.NewLine + this.Log;
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}


Model.cs
using System;
using System.Collections.Generic;
 
namespace VirtualQueryableCollectionViewBugDemo
{
    public class Row
    {
        public int Id { get; set; }
        public DateTime DateTime { get; set; }
        public TimeSpan TimeSpan { get; set; }
    }
 
    public static class Generator
    {
        public static int TestDataLength = 1 * 1000 * 1000;
        public static Random rng = new Random();
 
        public static List<Row> GenerateTestData()
        {
            var result = new List<Row>(TestDataLength);
 
            for (int i = 0; i < TestDataLength; i++)
            {
                string name = i.ToString();
                DateTime dateTime = new DateTime(rng.Next(1990, 2020), rng.Next(1, 12), rng.Next(1, 28));
                TimeSpan timeSpan = new TimeSpan(rng.Next(1, 23), rng.Next(1, 59), rng.Next(1, 59));
 
                result.Add(new Row()
                {
                    Id = i,
                    DateTime = dateTime,
                    TimeSpan = timeSpan
                });
            }
 
            return result;
        }
    }
}
Vera
Telerik team
 answered on 16 Dec 2011
0 answers
389 views
I want to validate my RadGridView manually by pressing a button, but I cant' get this to work. If I set the validator to ValidatesOnTargetUpdated="True" the validation works, but I want to trigger this validaton manually. Here is the XAML code of my DataColumn:

<telerik:GridViewDataColumn Header="Error" >
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <telerik:GridViewCell>
                <telerik:GridViewCell.DataContext>
                    <Binding NotifyOnValidationError="True" >
                        <Binding.ValidationRules>
                            <validators:MyValidator  />
                        </Binding.ValidationRules>
                    </Binding>
                </telerik:GridViewCell.DataContext>
                <telerik:GridViewCell.Style>
                    <Style TargetType="{x:Type telerik:GridViewCell}" >
                        <Style.Triggers>
                            <Trigger Property="Validation.HasError" Value="true">
                                <Setter Property="ToolTip"
                                    Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                                    Path=(Validation.Errors)[0].ErrorContent}"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </telerik:GridViewCell.Style>
                <telerik:GridViewCell.Content>
                    <TextBlock Text="!!!" />
                </telerik:GridViewCell.Content>
            </telerik:GridViewCell>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

I' ve managed to get the validator in codebehind and check every item in the datagrid, but I also have to set the bindings as invalid for the cells to display the error. I found the command System.Windows.Controls.Validation.MarkInvalid() for this, but for this command to work I need to get the binding expression of every cell. How can I get these binding expressions?
Davidm
Top achievements
Rank 1
 asked on 16 Dec 2011
3 answers
1.2K+ views
Hello,

I wanted to know how can I make the slider thumb to jump to the position where I click on the slider. In other words, how can I retrieve the value where the user clicked on the slider (and then I could set the slider's value).

Thank you
Petar Mladenov
Telerik team
 answered on 16 Dec 2011
1 answer
143 views
Dear Support,

i templated the DropDownContent like this,

<DataTemplate x:Key="outlookBaItemDropDownContentTemplate">
    <StackPanel Orientation="Horizontal">
        <Image Source="{Binding SmallIcon}"
               Width="20" />
        <Label Content="{Binding Header}" />
    </StackPanel>
</DataTemplate>


however the dropdown was originally intendet to use two columns, -
one for the icon, one for the header.

How can I make the items fit anyway?


Thanks in advance Martin
Petar Mladenov
Telerik team
 answered on 16 Dec 2011
1 answer
313 views
Dear Support!

I am using RadControls_for_WPF_2011_3_1205_DEV_hotfix.

When I set RadBusyIndicator.IsBusy="True" and operating system is running a cpu hungry process, I can click on the RadBusyIndicator content before RadBusyIndicator show busy content (refer attachment).

Please let me know how to resolve the issue.

MainWindow.xaml
<Window x:Class="RadBusyIndicatorDemo.MainWindow"
        Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen">
     
    <StackPanel>
        <TextBlock x:Name="textBlock" />
        <telerik:RadBusyIndicator IsBusy="True">
            <StackPanel>
                <Button Content="Button1" Click="Button_Click"/>
                <telerik:RadGridView ItemsSource="{Binding Items}" Height="300" />
            </StackPanel>
        </telerik:RadBusyIndicator>
    </StackPanel>
</Window>


MainWindow.xaml.cs
namespace RadBusyIndicatorDemo
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            this.DataContext = new MainViewModel();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.textBlock.Text = "clicked!"; // shouldn't happen
        }
    }
}
Ivo
Telerik team
 answered on 16 Dec 2011
5 answers
124 views
Hello Telerik,
I've got a RadGridView that has some columns... when I scroll down the grid and there's a column content that doesn't fit the column width it enlarges the column to content's size... if I'm not wrong there is a property for setting not to enlarge... but I can't find it, can you please help me?

Thanks
Vlad
Telerik team
 answered on 16 Dec 2011
1 answer
136 views
Hello,

I have a treelistview.  When user right click on an item and applies filter then I add one FilterDescriptor to the treelistview.
But it tries to filter on all the rows. My requirement is when user right click on any item then the filter should be applied only to the expanded nodes, not to those are collapsed nodes.

I have treelistview having upto 7 levels of expanded nodes. What i want is when user applies filter descriptor then it should filter all the data whose first level is expanded

Level 1 Level 2 Level 3 Level 4 Level 5 Level 6 Level 7
(-) Org
Dept 1
Cell 1
Mgr 1
Lead 1
Resp 1
Work1
Work2
Work3
Resp 2
Work4
Work5
Work6
(+) Dept 2
(+) Dept 3
(-) Dept4
Cell 4
Mgr 4
Lead 4
Resp 4
Work1
Work2
Work3
Resp 5
Work4
Work5
Work6
Dept 2 & Dept 3 are not in expanded state. While I filter I want the filter should be applied to those records of Dept 1 (Resp1, Resp2) & Dept 4 (Resp4 & Resp5)only
User can right click on Level 7 data only
Vlad
Telerik team
 answered on 16 Dec 2011
1 answer
149 views
We develop using the mvvm-pattern. While the VirtualQueryableCollectionView can be easily created in the code-behind, I would prefer to create it as a StaticResource in the View, as it is View-specific and doesn't belong in the ViewModel.

How would I create it as a resource? I would have liked to write something like:

 

<UserControl.Resources>
    <telerik:VirtualQueryableCollectionView x:Key="VirtualizedTransactions" 
        LoadSize
="10" 
        
ItemsSource="{Binding AllTransactions}" 
    />
</UserControl.Resources>

 


Any thoughts are appreciated.
Vlad
Telerik team
 answered on 16 Dec 2011
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
DataPager
PersistenceFramework
Styling
TimeBar
OutlookBar
TransitionControl
FileDialogs
Book
ToolBar
ColorPicker
TimePicker
MultiColumnComboBox
SyntaxEditor
VirtualGrid
NavigationView (Hamburger Menu)
Wizard
ExpressionEditor
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
Callout
PasswordBox
SplashScreen
Localization
Rating
Accessibility
CollectionNavigator
AutoSuggestBox
Security
VirtualKeyboard
HighlightTextBlock
TouchManager
StepProgressBar
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Hiba
Top achievements
Rank 1
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Max
Top achievements
Rank 1
Veteran
Iron
Alina
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Hiba
Top achievements
Rank 1
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Max
Top achievements
Rank 1
Veteran
Iron
Alina
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?