Telerik Forums
UI for WPF Forum
6 answers
1.7K+ views
I need to change the CellTemplate of a RadGridView. All of the examples I can find online defines the Columns statically in the Xaml, and then in that Column tag, they define the CellTemplate:

    <telerik:RadGridView AutoGenerateColumns="False" ItemsSource="{Binding}" RowStyleSelector="{StaticResource styleSelector}">
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding ID}" CellTemplateSelector="{StaticResource templateSelector}" />
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

The above example loads the CellTemplate only for the column with the heading "ID", and does that for all of the cells in that column. 

I have managed to load the CellTemplates in the code behind but this required me to pass an instance of the whole grid to the ViewModel, and also had to add a dependency Property to the GridView to bind the Columns of the grid to a GridViewColumnCollection in the ViewModel. 

This is a very messy workaround, one that I'm sure will get me fired if seen by the wrong eyes. What I need to do is something similar to this:

    <telerik:RadGridView.CellTemplateSelector>
        <local:MyTemplateSelector>
            <local:MyTemplateSelector.NormalTemplate>
                <DataTemplate>
                    ...Some [Normal] template...
                </DataTemplate>
            </local:MyTemplateSelector.NormalTemplate
            <local:MyTemplateSelector.DropdownTemplate>
                <DataTemplate>
                    ...Some [ComboBox] template...
                </DataTemplate>
            </local:MyTemplateSelector.DropdownTemplate>
        </local:MyTemplateSelector>
    </telerik:RadGridView.CellTemplateSelector>

I honestly have no idea why this RadGridView makes it so difficult to change the CellTemplate, because this prevents you from changing a common property such as the Foreground Color in the Label found in the ContentTemplate in the Cell itself.. Any ideas as to what I can do?
Joel Palmer
Top achievements
Rank 2
 answered on 12 Aug 2015
1 answer
93 views
Does anyone have a CRUD example that works on sizable data sets?

I've been banging my head against this for a couple of weeks.

DataForm won't work - it's sequential, one-record-at-a-time interface is too tedious for more than a half-dozen records.

In-cell editing in GridVIew won't work - if the records have more fields than can be displayed in a row.

Using the DataForm as row-detail for a GridView shows promise, but the example doesn't show how to handle inserts, deletes, or save confirmations, or how to handle failed updates.

Using a DataForm Synchronized with a GridView also shows promise, but it works in a way that simply won't work, for the usual business cases.

Take a look at the "DataForm ICollectionView Synchronization" demo.  It's really neat how you can navigate in the form and see the current row in the grid change, and vice versa.

Now try editing a row.  Change a name.  But don't click OK or Cancel, select a different row in the grid.  Or click a prev/next button in the DataForm.

What happened to the data?  If you go back to it, it looks like the form did an implicit OK.

If you were listening for the DataForm's EditEnding event, so you could update the database, and return Cancel = true, if something went wrong, sorry.  EditEnding never fired.  The database wasn't changed, but the grid and the form and the underlying collection were.

So maybe we're supposed to update the database from within the collection or the record objects.  Well we can't do it from within the record's EndEdit() method, because from there we have no way of knowing whether we should be doing an insert or a delete.

So maybe we need to be looking at the collection's CurrentChanging event? 

Digging into this, it seems that a QueryableCollectionView has a CurrentAddItem and a CurrentEditItem - and if we set e.Cancel = true if either of these is non-null, we can prevent the form from moving to a new record - but this doesn't stop the grid from moving to a new record.  And, oddly enough, if you edit a field in the grid, then select a new row, CurrentChanging fires, but CurrentEditItem is null.

So we're back where we started - with a set of demos that show of some really nice glitz, but have enormous holes when it comes to building something that is actually useful.
 
Kathy Schmidt
Top achievements
Rank 1
 answered on 12 Aug 2015
4 answers
88 views

I have a requirement where I need to pop a window up in order to show the detail of the selected tree node.  I need it to pop up in a location just to the right of what I selected in the TreeListView.

I figure this could be done using the Mouse Location or the Location relative to the selected node.  I haven't been able to get either to work. 

My approach is to pop up a simple Tool window at that location.  The better solution would be to have an EditTemplate that pops into its own window; but, I'm not sure if that is possible.  I have a good EditTemplate (shown) but the user demands that the tree remain very skinny and doesn't want to move things around much because this is a Touch Pad.

I'm open to whatever approach is the easiest code to maintain.  Thanks in advance for your help.

Here are my DataTemplates:

<DataTemplate
    x:Key="TreeNodeTemplate">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
 
        <Image
            Grid.Column="0"
            Source="{Binding Image, Mode=TwoWay}"
            ToolTip="{Binding Barcode, Mode=TwoWay}"/>
 
        <Image
            Grid.Column="0"
            Height="20"
            Width="20"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Margin="-20,0,0,0"
            Source="{Binding StatusImage, Mode=TwoWay}"
            ToolTip="{Binding StatusName, Mode=TwoWay}"/>
 
        <TextBlock
            Grid.Column="1"
            Text="{Binding Name, Mode=TwoWay}"
            Margin="5"
            ToolTip="{Binding Description}"/>
    </Grid>
</DataTemplate>
<DataTemplate
    x:Key="TreeNodeEditTemplate">
 
    <StackPanel
        Orientation="Horizontal">
        <Image
            Source="{Binding Image, Mode=TwoWay}"
            VerticalAlignment="Top"/>
 
        <Grid
            Margin="5"
            Background="Cornsilk">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
 
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="125"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
 
                <Grid.RowDefinitions>
                    <RowDefinition Height="28"/>
                    <RowDefinition Height="28"/>
                    <RowDefinition Height="28"/>
                    <RowDefinition Height="28"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
 
                <Label
                    Content="ID:"
                    Grid.Column="0"
                    Grid.Row="0"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"/>
 
                <TextBlock
                    Grid.Column="1"
                    VerticalAlignment="Center"
                    Text="{Binding ID, Mode=TwoWay}"/>
 
                <Label
                    Content="Name:"
                    Grid.Column="0"
                    Grid.Row="1"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"/>
 
                <TextBox
                    Grid.Column="1"
                    Grid.Row="1"
                    VerticalAlignment="Center"
                    Text="{Binding Name, Mode=TwoWay}"
                    IsEnabled="{Binding IsEditableStatus}"
                    IsReadOnly="{Binding IsEditableStatus, Converter={StaticResource BoolToOppositeBoolConverter}}"/>
 
                <Label
                    Content="Description:"
                    Grid.Column="0"
                    Grid.Row="2"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"/>
 
                <TextBox
                    Grid.Column="1"
                    Grid.Row="2"
                    VerticalAlignment="Center"
                    Text="{Binding Description, Mode=TwoWay}"
                    IsEnabled="{Binding IsEditableStatus}"
                    IsReadOnly="{Binding IsEditableStatus, Converter={StaticResource BoolToOppositeBoolConverter}}"/>
 
                <Label
                    Content="Barcode:"
                    Grid.Column="0"
                    Grid.Row="3"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"/>
 
                <TextBox
                    Grid.Column="1"
                    Grid.Row="3"
                    VerticalAlignment="Center"
                    Text="{Binding Barcode, Mode=TwoWay}"/>
            </Grid>
 
            <GroupBox
                Header="Status"
                Grid.Row="4"
                Margin="5">
 
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="125"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
 
                    <Grid.RowDefinitions>
                        <RowDefinition Height="28"/>
                        <RowDefinition Height="28"/>
                    </Grid.RowDefinitions>
 
                    <Label
                        Content="CRUD Status:"
                        Grid.Column="0"
                        Grid.Row="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"/>
 
                    <TextBlock
                        Grid.Column="1"
                        Grid.Row="0"
                        VerticalAlignment="Center"
                        Text="{Binding StatusName, Mode=TwoWay}"/>
 
                    <Label
                        Content="Inspect Status:"
                        Grid.Column="0"
                        Grid.Row="1"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"/>
 
                    <TextBlock
                        Grid.Column="1"
                        Grid.Row="1"
                        Text="{Binding InspectStatusName, Mode=TwoWay}"
                        VerticalAlignment="Center"/>
                </Grid>
            </GroupBox>
 
        </Grid>
    </StackPanel>
</DataTemplate>

 

 

Stefan
Telerik team
 answered on 12 Aug 2015
2 answers
131 views

Hi,

there is already a Question "Show validation after insert exception" but no fully answers :( for me.

So i had this problem.

Project ( is in MVVM with DataAccess ) and RadDataGrid

In case i add a new Record i catch the Event "RowEditEnded" to a Command with <telerik:EventBinding> in XAML and the

EventOperationType = GridViewEditOperationType.Insert is found.

Then i Save the Data to DB with DataAccess   context.SaveChanges() ; and DB is sending Back a Exception DuplicateKeyException

so Commit was not done. But Record was added to the Grid. Now i try to change the Attribute (PK) which raised the violation to a valid one and try the same again. The Event is raised "RowEditEnded" as wanted but now not in "Insert" Mode  has switched from  "GridViewEditOperationType.Insert" (as it was before on the Record)  to "GridViewEditOperationType.Edit" which is different in operation then the Insert a new Record in DB.

So Question is how could i tell the Grid not to do this automatic switch until commit is valid (without exception ) done. 

The Record should stay in Insert Mode until Storing was valid.

Or if there is a better solution to handling exceptions on DB side please let me know. 

thnx br thomas

 

 

 

 

 

 

Thomas
Top achievements
Rank 1
 answered on 12 Aug 2015
1 answer
134 views

Hello,

I want to override some functionality of the GridView combobox, datepicker and data column.

I overriden the class GridViewComboBoxColumn, but the functionality is not working.

My goal is for the combobox, when it receives focus it should show the dropdown, the user can then select the value with one enter and control should automatically move to the next field in the GridView.

The same functionality I want to implement for the DatePicker. And for the Textbox I want the enter function like the tab.

public class CustomGridViewComboBoxColumn : GridViewComboBoxColumn
{
    #region Fields
     
    private bool _isEnterInThisCombo = false;
 
    #endregion
     
    #region Constructor
     
    #endregion
     
    #region Methods
 
    private void ComboBox_PreviewKeyUp(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter && _isEnterInThisCombo)
        {
            if(this.IsVmEditMode && ! Validation.GetHasError(this))
            {
                CbIsCheckedForAudit = true;
            }
 
            this.MoveFocus(new TraversalRequest(System.Windows.Input.FocusNavigationDirection.Next));
 
            /* Reset flag */
            _isEnterInThisCombo = false;
        }
    }
 
    private void ComboBox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            _isEnterInThisCombo = true;
        }
    }
 
 
    private void ComboBox_Loaded(object sender, RoutedEventArgs e)
    {
        if (this.IsVmEditMode) // && this.SelectedValue == null)
            this.CbOpenDropDownOnFocus = true;
        else if (this.IsVmEditMode)
            this.CbOpenDropDownOnFocus = false;
        else
            this.CbOpenDropDownOnFocus = true;
    }
 
    #endregion
 
    #region Dependency Properties
 
    public bool CbOpenDropDownOnFocus
    {
        get { return (bool)GetValue(CbOpenDropDownOnFocusProperty); }
        set { SetValue(CbOpenDropDownOnFocusProperty, value);}
    }
 
    public static readonly DependencyProperty CbOpenDropDownOnFocusProperty =
        DependencyProperty.Register("CbOpenDropDownOnFocus", typeof(bool), typeof(CustomGridViewComboBoxColumn), new PropertyMetadata(false));
 
 
    public bool CbIsCheckedForAudit
    {
        get { return (bool)GetValue(CbIsCheckedForAuditProperty); }
        set { SetValue(CbIsCheckedForAuditProperty, value); }
    }
 
 
    public static readonly DependencyProperty CbIsCheckedForAuditProperty =
        DependencyProperty.Register("CbIsCheckedForAudit", typeof(bool), typeof(CustomGridViewComboBoxColumn), new PropertyMetadata(false));
 
 
    public virtual bool IsVmEditMode
    {
        get { return (bool)GetValue(IsVmEditModeProperty); }
        set { SetValue(IsVmEditModeProperty, value); }
    }
 
 
    public static readonly DependencyProperty IsVmEditModeProperty =
        DependencyProperty.Register("IsVmEditMode", typeof(bool), typeof(CustomGridViewComboBoxColumn), new PropertyMetadata(false));
 
    #endregion

 

Thanks in advance.

 

Marcel

Stefan
Telerik team
 answered on 12 Aug 2015
5 answers
150 views
Hi,

I think we are seeing a problem with Exporting when the class in the collection that the RadGridView binds to has a sub class, and one of the properties of that sub class has a converter on it. This is an example (Sub Item B is causing the trouble):
<telerik:RadGridView x:Name="testRadGridView" ItemsSource="{Binding ItemList}" AutoGenerateColumns="False">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=MainItemA}" Header="Main Item A " />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=MainItemB}" Header="Main Item B " />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=SubItem.SubItemA}" Header="Sub Item A" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=SubItem.SubItemB, Converter={StaticResource MyTestConverter}}" Header="Sub Item B" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

And this is the code:
   public class Item
   {
       public string  MainItemA { get; set; }
       public int  MainItemB { get; set; }
       public SubItem SubItem { get; set; }
   }
   public class SubItem
   {
       public string   SubItemA { get; set; }
       public DateTime SubItemB { get; set; }
   }
    public class TestConverter : IValueConverter
   {
       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           DateTime dateTimeValue = (DateTime)value;
            return dateTimeValue.ToString("yyyy-MM-dd HH:mm:ss");
       }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           throw new NotSupportedException();
       }
   }
 
   public class MainWindowViewModel
   {
       public ObservableCollection<Item> ItemList { get; set; }
 
        public MainWindowViewModel()
       {
           ItemList = new ObservableCollection<Item>();
 
           ItemList.Add(new Item { MainItemA = "Main Item A1", MainItemB = 1, SubItem = new SubItem { SubItemA = "Sub Item A1", SubItemB = new DateTime(2014,1,1,13,12,11) } });
           ItemList.Add(new Item { MainItemA = "Main Item A2", MainItemB = 2, SubItem = new SubItem { SubItemA = "Sub Item A2", SubItemB = new DateTime(1999, 4, 3, 2, 1, 0) } });
       }
   }

In the Export, the converter is not applied, and the output logging of VS contains this:
System.Windows.Data Error: 40 : BindingExpression path error: 'SubItem' property not found on 'object' ''ExportElement' (HashCode=6)'. BindingExpression:Path=SubItem.SubItemA; DataItem='ExportElement' (HashCode=6); target element is 'ValueSetter' (Name=''); target property is 'Value' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'SubItem' property not found on 'object' ''ExportElement' (HashCode=6)'. BindingExpression:Path=SubItem.SubItemB; DataItem='ExportElement' (HashCode=6); target element is 'ValueSetter' (Name=''); target property is 'Value' (type 'Object')


Product version 2013.3.1016.40, VS2010 SP1, Windows 7 x64.

Any ideas?

Dimitrina
Telerik team
 answered on 12 Aug 2015
3 answers
152 views

So I'm trying to customize the RadMaskedTextInput to where the errors line up.

Right now they popup right next to the textbox associated with them.

 I was thinking this could be possible by putting the textboxes in a fixed width grid and setting the horizontal alignment to left.

 I have attached the current way it looks and the way I want it to look like.

Any help would be appreciated.

Peshito
Telerik team
 answered on 12 Aug 2015
2 answers
179 views
Hi
I have a requirement to capture an image from webcam of Lap/PC and the captured image should be displayed in image editor.
How to do this one using Telerik UI for WPF.

Thanks,
Mohamed
Top achievements
Rank 1
 answered on 12 Aug 2015
1 answer
145 views

Hello,

I am working on a custom datagrid for my application and I want to have a custom column where the cell has a Textbox and a small button. When the user clicks the button a small screen must be shown where the user can enter some values. The total of the inputting values need to be displayed back in the gridview.
I am looking at implementing this, but have a hard time doing. I like to have the same style for the button and the subscreen as the datepicker/Calculatorpicker.
The content of the dropdown screen need to be replacable by other content using a usercontrol.

Whats the best way to implement this, should I create a custom control for this? And then create a custom column according to the approach below?

Or is there a better way to implement this?

http://docs.telerik.com/devtools/wpf/controls/radgridview/columns/how-to/create-date-time-picker-column.html

Thank in advance.

Marcel

Stefan
Telerik team
 answered on 11 Aug 2015
1 answer
215 views

I have used the wizard events to control my wizard navigation but once I cancel the navigation for one step using e.Cancel, The SelectionChanging/ SelectionChanged events doesn't  get fired. 

I was using the UI for WPF Q1 2015 and now updated to UI for WPF Q2 2015 but still the same problem exists.

 

check this code sample

 

using System.Windows;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;

namespace WizardNavigation
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private ObservableItemCollection<WizardPage> collection;
        private int cancelCounter = 1;
        public MainWindow()
        {
            InitializeComponent();

            collection = new ObservableItemCollection<WizardPage>();

            var firstPage = new WizardPage {Content = "My First Page Content"};

            var secondPage = new WizardPage {Content = "My Second Page Content"};

            var thirdPage = new WizardPage {Content = "My Third Page Content"};

            var fourthPage = new WizardPage {Content = "My Fourth Page Content"};

            myWizard.WizardPages.Add(firstPage);
            myWizard.WizardPages.Add(secondPage);
            myWizard.WizardPages.Add(thirdPage);
            myWizard.WizardPages.Add(fourthPage);

            myWizard.Next += myWizard_Next;
            myWizard.SelectionChanging += myWizard_SelectionChanging;
        }

        void myWizard_SelectionChanging(object sender, SelectedPageChangingEventArgs e)
        {
            if (cancelCounter != 2) return;
            e.Cancel = true;
            MessageBox.Show("Cancelled, Click again to navigate");
        }

        void myWizard_Next(object sender, NavigationButtonsEventArgs e)
        {
            // You will need to click the next twice for to move to step 3.
            // SelectionChanging will not be called on the second click
            //SelectionChanging will be called when moving to forth step.
            cancelCounter++;

            var wizard = sender as RadWizard;
            
            if (wizard.SelectedPage.Content == "My First Page Content")
            {
                e.SelectedPageIndex = 2;
            }
        }
    }
}

​

Yoan
Telerik team
 answered on 11 Aug 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Iron
Iron
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Richard
Top achievements
Rank 4
Bronze
Bronze
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Iron
Iron
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Richard
Top achievements
Rank 4
Bronze
Bronze
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?