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

Is it possible to 'preview edit' or enable one-click editing?

5 Answers 147 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jacob
Top achievements
Rank 1
Jacob asked on 26 Sep 2011, 10:41 PM
I'm currently evaluating the GridView control for a project and am trying to determine if it supports a feature I would like to have. I've searched for this and found nothing, but I'm not sure if there's a common name for the feature I'm unaware of.

What I would like is the ability to show the editor template for a cell on a certain trigger, but without the row/cell entering edit mode; it'd be a sort of 'preview edit' mode. Then, when the control gains focus it would enter 'true' edit mode.

This might make more sense in context. Say I have a column displaying dates, and the editor I want to use is a standard .NET DatePicker. To edit this value I would like it to work like this: when I mouse-over a cell in that column, the editor template appears for that cell. Then, I can click into the editor textbox or click on the button that launches the popup; either of these would enter edit mode. This would allow me to edit the value with one fewer click than I'm currently able to.

Is this supported and I'm missing it, or is it possible to write myself, or just completely unsupported? Thanks.

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 27 Sep 2011, 09:09 AM
Hi Jacob,

I believe it is easily achievable . You can place any control in the cell when in display mode. Using the CellTemplate property of the column , you can replace the standard TextBlock with your control and inside the template wire up the events needed.

In case you need further help adjusting this approach to your production code , do not hesitate to contact us.


Best wishes,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jacob
Top achievements
Rank 1
answered on 29 Sep 2011, 07:18 PM
Swapping the control displayed when the mouse is over is trivial. I don't see how to cleanly move into edit mode, though.

Here's what I threw together as a simple test...
<!-- The Column's CellTemplate -->
<DataTemplate x:Key="DateCellTemplate" DataType="m:ModelObject">
    <Control>
        <Control.Style>
            <Style TargetType="Control">
                <!-- Default template is just a text block -->
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <TextBlock Text="{Binding SomeDate, StringFormat=d}" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                 
                <EventSetter Event="PreviewGotKeyboardFocus" Handler="OnPreviewGotKeyboardFocus" /> <!-- (or some similar event) -->
                 
                <!-- Show the editor template when the mouse is over -->
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <DatePicker SelectedDate="{Binding SomeDate}" SelectedDateFormat="Short" />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>                               
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Control.Style>
    </Control>           
</DataTemplate>
 
<!-- The Column's CellEditorTemplate -->
<DataTemplate x:Key="DateCellEditorTemplate" DataType="m:ModelObject">
    <DatePicker SelectedDate="{Binding SomeDate}" SelectedDateFormat="Short">
</DataTemplate>

// and the handler
private void OnPreviewGotKeyboardFocus(object sender, RoutedEventArgs e) {
    var gvc = ((Control)sender).ParentOfType<GridViewCell>();
    gvc.BeginEdit();
}



What I want is:
  • Date column displays a text block by default
  • DatePicker is shown on mouseover (but cell is not being edited yet)
  • Interact with DatePicker (click inside the textbox, or click the calendar button) and 1) the interaction goes through and 2) the cell enters edit mode

What I mean by 'the interaction goes through' is, if you click the calendar button, the calendar popup appears as expected, if you click the text box focus goes there.

My code above gets me almost there; the problem is that the DatePicker originally clicked on is not the same DatePicker as in the editor template. So the popup does not get shown (or it does, but is invisible by that point).

This isn't a super important use case for me, but I've noticed that at least one other offering I'm considering differentiates the concepts of 'showing a cell editor' and 'editing a cell' and it struck me as a useful feature to have.
0
Pavel Pavlov
Telerik team
answered on 05 Oct 2011, 09:20 AM
Hi Jacob,

I am attaching a small sample project based on your snippets with some modifications.

The idea is - we do not actually need to enter edit mode. We can use the original editor from the cell template to edit the underlying value . All we need is just bind it two way.

Please check the behavior of the sample attached and let me know if it does not match your final requirement.

I have added some Debug.Writeline code in the setter of the property so you can check that this approach property updates the underlying value.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jacob
Top achievements
Rank 1
answered on 05 Oct 2011, 07:50 PM
Thanks for taking the time to look at this. I agree that that sample gets us most of the way there and captures the spirit of what I'm trying to do. Unfortunately though, since the 'real' editing plumbing is not getting hooked up, there are a few inconsistencies. From a quick look these include
  • Mouse over, click on the editing text box, then mouse out. The editor goes away, whereas the click/focus should've locked the cell into edit mode. This could probably be fixed by more complicated templates/triggers, but it would be tricky, and in any case, more work for us.
  • IEditableObject support would be lost.
  • The 'editing' UI hint for the row is not shown. For consistency I think we'd have to make all columns work in this same way, which would essentially be ignoring (or re-implementing) the whole 'editing' layer of the grid

I'm also worried that, not knowing the internals of the gridview and its editing model, there would be additional inconsistencies.

Again, not a deal-breaker, I was just wondering if this feature was there and I missed it.
0
Pavel Pavlov
Telerik team
answered on 11 Oct 2011, 09:22 AM
Hello Jacob,

Well I believe this is as close as we can get without tweaking the default templates and behaviors to an unsupportable level .

Do not hesitate to contact us in case you find other troubles using RadGridView or just  need assistance in solving an issue.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Jacob
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Jacob
Top achievements
Rank 1
Share this question
or