Select cell content when readonly

8 posts, 0 answers
  1. Frederic Gos
    Frederic Gos avatar
    3 posts
    Member since:
    May 2006

    Posted 01 Mar 2010 Link to this post

    Hi,

    I have a RadGridView with CanUserSelect="True". I define my columns manually using nested GridViewDataColumn. Each column is bound to some property of some object. The properties only have a 'get' method. When i run my app, I cannot select the content of the cells (for copy operation). I noticed that if i change the properties of the underlying objects and add an empty setter, I get to edit.

    How can I do the same things without having to change my properties? I want to be able to have readonly data that I CAN select. Is there a way to tell the columns or the whole  grid that they should be selectable? (I thought btw that 'CanUserSelect' should take care of that?)

    brgds
    Frederic
  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 04 Mar 2010 Link to this post

    Hello Frederic,

    By default RadGridView will set each column to read-only when the underlying property is read-only. However this did not prevent you from selecting a specific row and do copy paste operation.

    If your desired behavior is to have copy paste like in edit mode, but without entering into edit, my suggestion is to create custom CellTemplate for each column that has read-only TextBox. Here is a sample XAML snippet:
    <telerik:GridViewDataColumn Header="MyProperty" DataMemberBinding="{Binding MyProperty}">
        <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                <TextBox Text="{Binding MyProperty}" IsReadOnly="True" core:StyleManager.Theme="Office_Black" />
            </DataTemplate>
        </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>


    Regards,
    Stefan Dobrev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rudis
    Rudis avatar
    30 posts
    Member since:
    Feb 2010

    Posted 22 Sep 2010 Link to this post

    Hello!

    A problem I have with this solution is that the row doesn´t get selected when clicking on the readonly text. I have to hit an area outside the TextBox. Do we have a catch 22 here? Is it because the TextBox is readonly?

    /Anna

  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 22 Sep 2010 Link to this post

    Hi Anna Rudlund,

    This is actually caused by the TextBox itself - mouse events do not reach the grid since they are handled by the TextBox control. One possible workaround is to manually handle mouse events and select the corresponding rows. 

    public MainWindow()
    {
        InitializeComponent();
      
        this.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnMouseDown), true);
    }
      
    private void OnMouseDown(object sender, MouseButtonEventArgs e)
    {
        var senderElement = e.OriginalSource as FrameworkElement;
        var row = senderElement.ParentOfType<GridViewRow>();
      
        if (row != null)
        {
            row.IsSelected = true;
        }
    }


    Regards,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Rudis
    Rudis avatar
    30 posts
    Member since:
    Feb 2010

    Posted 28 Sep 2010 Link to this post

    Thanx!

    That solved my problem.

    Best regards,
    Anna
  7. Rex Walker
    Rex Walker avatar
    7 posts
    Member since:
    Oct 2009

    Posted 11 Feb 2012 Link to this post

    Just a quick followup on allowing select/copy operation on a cell.

    I have found the use of a CellEditTemplate to be ideal for this type of functionality.

    <telerik:GridViewDataColumn Header="MyProperty" DataMemberBinding="{Binding MyProperty}">
      
        <telerik:GridViewDataColumn.CellEditTemplate>
      
            <DataTemplate>
      
                <TextBox Text="{Binding MyProperty}" IsReadOnly="True" BorderThickness="0" Margin="0"  />
      
            </DataTemplate>
      
        </telerik:GridViewDataColumn.CellEditTemplate>
      
    </telerik:GridViewDataColumn>
  8. Fabrizio
    Fabrizio avatar
    16 posts
    Member since:
    Nov 2013

    Posted 13 Nov 2014 in reply to Rex Walker Link to this post

    Great: just what I was looking for!

    Thank you, Rex Walker.
  9. NA
    NA avatar
    1 posts
    Member since:
    Sep 2016

    Posted 27 Sep in reply to Rex Walker Link to this post

    Hi Rex,
    I'm having the same requirement, so I come across this post. I tried your solution, but the only issue is:
    In order to select the content, I have do the single click TWICE: the 1st click will enter the edit mode and place the cursor inside the textbox, and I have to do a 2nd click to select the content, which is not that intuitive. (If after the 1st click and I move the mouse without releasing the button, it performs a drag action. Yes, my app will allow drag & drop.)

    What I want to achieve: When mouse over the text field, the cursor turns to IBeam, so the user can directly select the contect with only one click. If this is too hard to achieve, alternatively I can do, when the user click on text field, all the text are selected.

    Do you have any idea about how I achieve this please? Thanks!
Back to Top
UI for WPF is Visual Studio 2017 Ready