Custom Cell editor

11 posts, 0 answers
  1. Perlom
    Perlom avatar
    33 posts
    Member since:
    Aug 2011

    Posted 24 Aug 2011 Link to this post

    Hi,
    We need to have a RadGridView containing a bound column that could hold a long text (up 4000 char). Each cell if the column will have a little button on the side, and would just show a portion of the text. When the user clicks on the button, an editor popups (ideally in adjacent to the clicked cell) and user can edit the entire text and save it back to cell. Is that doable with the RdaGrdiView? Any help would be much appreciated.
    Thanks
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 24 Aug 2011 Link to this post

    Hi Perlom,

    This should be fairly easy to achieve.
    The GridViewDataColumn has two properties : CellTemplate and CellEditTemplate. They respectively control what should be shown in display and edit mode.
    So in your case you may put the big and heavy text box in a DataTemplate  and set this DataTemplate to the CellEditTemplate property of the column .
    For the display mode you may leave the light default TextBox.

    In case you have troubles implementing the above described , just let me know.

    Greetings,
    Pavel Pavlov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Perlom
    Perlom avatar
    33 posts
    Member since:
    Aug 2011

    Posted 24 Aug 2011 Link to this post

    Thanks Pavel for the prompt response.  Is there a way to send me a link to an example that illustrate that?  I don’t want the entire row to expand, just maybe a sliding window in below the cell that spans in top of other rows.

     

    Cheers

  5. Perlom
    Perlom avatar
    33 posts
    Member since:
    Aug 2011

    Posted 24 Aug 2011 Link to this post

    I have found this sample in another thread here. It exactly does what I want but with the color picker instead.  I have been trying to use the same way but with a textbox, but no avail all day!!! any idea how should I go about this?? Here is the link:

    http://www.telerik.com/help/wpf/radgridview-howto-create-custom-editor.html


    Regards
  6. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 25 Aug 2011 Link to this post

    Hi Perlom,

    Yes that is the link. As I am not sure what the trouble is . You can just paste me the implementaton of your business object and the property you need edited. I will gather a small runnable sample for you with your object.

    All the best,
    Pavel Pavlov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  7. Perlom
    Perlom avatar
    33 posts
    Member since:
    Aug 2011

    Posted 25 Aug 2011 Link to this post

    Hi Pavel,

    Thank you for the help. Here is the Cutsome control for the Column that I did based on the color picker exapmle.

    Cheers

    public class RadTextPopupEditColumn : GridViewBoundColumnBase
    {
    static RadTextPopupEditColumn()
    {
    DefaultStyleKeyProperty.OverrideMetadata(typeof (RadTextPopupEditColumn),
    new FrameworkPropertyMetadata(typeof (RadTextPopupEditColumn)));
    }

    public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
    {
    var cellElement = new StackPanel();

    var valueBinding = new Binding(this.DataMemberBinding.Path.Path)
    {
    Mode = BindingMode.OneTime,
    };

    var button = new RadButton
    {
    Content = "...",
    Width = 15,
    HorizontalAlignment = HorizontalAlignment.Stretch
    };

    var txtbox = new TextBox
    {
    Width = 100
    };

    txtbox.SetBinding(TextBox.TextProperty, valueBinding);

    cellElement.Orientation = Orientation.Horizontal;
    cellElement.Children.Add(txtbox);
    cellElement.Children.Add(button);

    return cellElement;
    }

    public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
    {
    // I tried this code to popup a larger textbox to edit, but it didn't work

    var cellEditElement = new TextBox();
    this.BindingTarget = TextBox.TextProperty;
    cellEditElement.Text = this.Text;
    var valueBinding = this.CreateValueBinding();
    cellEditElement.SetBinding(TextBox.TextProperty, valueBinding);

    cellEditElement.Height = 200;

    return cellEditElement;
    }

    private Binding CreateValueBinding()
    {
    var valueBinding = new Binding
    {
    Mode = BindingMode.TwoWay,
    NotifyOnValidationError = true,
    ValidatesOnExceptions = true,
    UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
    Path = new PropertyPath(this.DataMemberBinding.Path.Path)
    };
    return valueBinding;
    }

    public override void CopyPropertiesFrom(Telerik.Windows.Controls.GridViewColumn source)
    {
    base.CopyPropertiesFrom(source);
    var rmpTextEditorColumn = source as RadTextPopupEditColumn;
    if (rmpTextEditorColumn != null)
    {
    this.Text = rmpTextEditorColumn.Text;
    }
    }

    public static readonly DependencyProperty TextProperty =
    DependencyProperty.Register("Text", typeof (string), typeof (RadTextPopupEditColumn),
    new PropertyMetadata(default(string)));

    public string Text
    {
    get { return (string) GetValue(TextProperty); }
    set { SetValue(TextProperty, value); }
    }
    }

     public class SampleData : INotifyPropertyChanged
        {
            private string _FirstName;

            public string FirstName
            {
                get { return _FirstName; }
                set
                {
                    if (value != _FirstName)
                    {
                        _FirstName = value;
                        OnPropertyChanged("FirstName");
                    }
                }
            }

            private string _LastName;

            public string LastName
            {
                get { return _LastName; }
                set
                {
                    if (value != _LastName)
                    {
                        _LastName = value;
                        OnPropertyChanged("LastName");
                    }
                }
            }

            private int _Age;

            public int Age
            {
                get { return _Age; }
                set
                {
                    if (value != _Age)
                    {
                        _Age = value;
                        OnPropertyChanged("Age");
                    }
                }
            }

            private Color _FavouriteColor;

            public Color FavouriteColor
            {
                get { return _FavouriteColor; }
                set
                {
                    if (value != _FavouriteColor)
                    {
                        _FavouriteColor = value;
                        OnPropertyChanged("FavouriteColor");
                    }
                }
            }

            private string _Notes;

            public string Notes
            {
                get { return _Notes; }
                set
                {
                    if (value != _Notes)
                    {
                        _Notes = value;
                        OnPropertyChanged("Notes");
                    }
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;
            protected void OnPropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    <Window x:Class="TextPopupEditGrid.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"
            xmlns:TextPopupEditGrid="clr-namespace:TextPopupEditGrid" Title="MainWindow" Height="350" Width="525">
        <Grid x:Name="LayoutRoot" Background="White">

            <Grid.Resources>
                <telerik:ColorToBrushConverter x:Key="colorToBrushConverter" />
            </Grid.Resources>

            <telerik:RadGridView x:Name="radGridView" AutoGenerateColumns="False" ItemsSource="{Binding}">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn UniqueName="FirstName" DataMemberBinding="{Binding FirstName}" Header="FirstName" />
                    <telerik:GridViewDataColumn UniqueName="LastName" DataMemberBinding="{Binding LastName}" Header="LastName" />
                    <telerik:GridViewDataColumn UniqueName="Age" DataMemberBinding="{Binding Age}" Header="Age" />

                    <TextPopupEditGrid:RadColorPickerColumn UniqueName="FavouriteColor" DataMemberBinding="{Binding FavouriteColor}"
                                           Header="FavouriteColor" MainPalette="ReallyWebSafe"/>

                    <TextPopupEditGrid:RadTextPopupEditColumn UniqueName="FavouriteColor" DataMemberBinding="{Binding Notes}"
                                           Header="Notes" />

                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

        </Grid>

    </Window>

  8. Perlom
    Perlom avatar
    33 posts
    Member since:
    Aug 2011

    Posted 27 Aug 2011 Link to this post

    If this seems to be too hard, anybody has any other sugestion to achieve the same result?
  9. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 31 Aug 2011 Link to this post

    Hello Perlom,

    I am attaching the sample promised.

    Regards,
    Pavel Pavlov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  10. Perlom
    Perlom avatar
    33 posts
    Member since:
    Aug 2011

    Posted 31 Aug 2011 Link to this post

    Thumbs up Pavel, that’s what I was looking for :)

     

    Cheers!!!

  11. Franz
    Franz avatar
    2 posts
    Member since:
    Feb 2016

    Posted 12 Oct Link to this post

    The link to attached sample "Sample.zip" seems to be dead.

    Would you please so kind as to restore it?

  12. Stefan X1
    Admin
    Stefan X1 avatar
    518 posts

    Posted 17 Oct Link to this post

    Hello Franz,

    This was due to the technical issues we experienced with the attachments and links in our forum threads. However, the problem has been resolved. Can you please try again to download the sample project attached by my colleague?

    Best Regards,
    Stefan X1
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready