Editing within Cell Template

6 posts, 0 answers
  1. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 09 Jan 2012 Link to this post

    I have seen similar questions like this asked on this forum, but none seem to be answering what I need to have done.   If someone could help or point me in the right direction, that would be great.

    I am trying to display a grid that has 15 columns or so.  Three of them are editable, the rest are not.   Rather than creating an edit template, I chose to put text boxes in the cell template so that these editable cells are always "in edit mode".   I do not want to have to edit the record first before being able to change values.

    The problem I am encountering is that the tab key doesn't seem to work right.   When you come from a previous cell that is just a text block, it will tab to the cell itself rather than the text box it contains.  You have to hit tab once again in order for it to select the textbox.   Setting the entire grid to read only didn't help either.

    What can I do to force the focus to the text box when the cell has focus?
                <telerik:RadGridView x:Name="uxMasterPricingGrid" RowIndicatorVisibility="Collapsed" 
                                 ShowGroupPanel="False" IsReadOnly="true" AutoGenerateColumns="false"
                                 Grid.Row="1" TabIndex="0" >
                    <telerik:RadGridView.Columns>
     
                        <telerik:GridViewDataColumn Header="Unit Cost" TextAlignment="Right"
                                 HeaderTextAlignment="Center" MinWidth="50" >
     
                        <telerik:GridViewDataColumn Header="Base Price" TextAlignment="Right"
                                 HeaderTextAlignment="Center" MinWidth="50" >
                            <telerik:GridViewDataColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBox Text="{Binding BasePrice.Current, Mode=TwoWay}"
                                             BorderThickness="0" Background="Transparent"
                                             Foreground="{Binding BasePrice.Foreground}"
                                             LostFocus="BasePrice_LostFocus"
                                             TextChanged="BasePrice_TextChanged"></TextBox>
                                </DataTemplate>
                            </telerik:GridViewDataColumn.CellTemplate>
                        </telerik:GridViewDataColumn>
     
    :                                         :                                         :

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 10 Jan 2012 Link to this post

    Hi Steven,

    Why don't you try setting EditTriggers property of RadGridView to CellClick ? Thus you will need only a single click (without first making the cell current) to start editing it.
    You can define the property as follows:

    <telerik:RadGridView Name="clubsGrid"
                                 ItemsSource="{Binding Clubs}"
                                 EditTriggers="Default,CellClick">
     
    Will that approach fit into your requirements ? 

    Greetings,
    Maya
    the Telerik team

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

  3. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 10 Jan 2012 Link to this post

    Maya,

    No, that will not work because the problem is not clicking, the problem is the TAB key.
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 10 Jan 2012 Link to this post

    Hello Steven,

    Generally, my idea was that you can set the EditTriggers property in the above-mentioned way and do not define CellTemplate for the columns. Thus you will be able to edit a cell value on a single click.  
    Is the reason for placing a TextBox in CellTemplate only for minimizing the number of clicks or you have another idea in mind ? 

    Regards,
    Maya
    the Telerik team

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

  5. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 10 Jan 2012 Link to this post

    Maya,

    Thank you for your quick reply.

    I thought about that originally, but decided not to because of needing to manage the edit mode and was worried that I had to deal with various events (after reading a number of postings here) to keep it in edit mode.   Now in hindsight, it seems I still need to do some event handling in order to use a cell template.   Perhaps I could try the edit mode way and see if that works.

    When the screen first opens, where (i.e. what event handler) is the best place to put the BeginEdit?




  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Jan 2012 Link to this post

    Hi Steven,

    Actually, placing the grid into edit mode on starting the application is a bit difficult as the window steals the focus and although RadGridView visually looks in edit mode, the focus is not on it and you cannot start typing immediately. 
    Yet another possible approach that came to my mind is to create your own custom column with a TextBox and once the corresponding cell it tabbed to, to focus this TextBox. I am sending you a sample project illustrating the suggested approach. Will that fit into your scenario ? 

    All the best,
    Maya
    the Telerik team

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

Back to Top