This is a migrated thread and some comments may be shown as answers.

Select cell content when readonly

7 Answers 900 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frederic Gos
Top achievements
Rank 1
Frederic Gos asked on 01 Mar 2010, 03:45 PM
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

7 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 04 Mar 2010, 09:07 PM
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.
0
Rudis
Top achievements
Rank 1
answered on 22 Sep 2010, 07:30 AM
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

0
Milan
Telerik team
answered on 22 Sep 2010, 12:04 PM
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
0
Rudis
Top achievements
Rank 1
answered on 28 Sep 2010, 12:59 PM
Thanx!

That solved my problem.

Best regards,
Anna
0
Rex Walker
Top achievements
Rank 1
answered on 11 Feb 2012, 06:22 PM
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>
0
Fabio
Top achievements
Rank 1
answered on 13 Nov 2014, 03:29 PM
Great: just what I was looking for!

Thank you, Rex Walker.
0
NA
Top achievements
Rank 1
answered on 28 Sep 2016, 01:13 AM
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!
Tags
GridView
Asked by
Frederic Gos
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Rudis
Top achievements
Rank 1
Milan
Telerik team
Rex Walker
Top achievements
Rank 1
Fabio
Top achievements
Rank 1
NA
Top achievements
Rank 1
Share this question
or