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

Setting a newly inserted row in a RadGridView to edit mode from View Model

3 Answers 328 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Justin D.
Top achievements
Rank 1
Justin D. asked on 24 Jan 2011, 09:54 PM
Hello. We are using RadControls for Silverlight Q3 2010. We are currently using the evaluation version but plan to purchase the full suite next month.

I am using a RadGridView. In summary, the problem is that when a row is inserted, we want that new row to be in edit mode. I'm not sure how to do this. The AddingNewDataItem event is not firing.

We have a button for them to add the new item to the grid. We do not allow them to use the insert key.

[Note: I have modified the names of our business objects for simplification.]

Here is the XAML for the grid.

<telerik:RadGridView x:Name="FooGrid"
                     CanUserFreezeColumns="False" 
                     GridLinesVisibility="Horizontal" 
                     IsFilteringAllowed="False"
                     ShowGroupPanel="False"
                     ItemsSource="{Binding CurrentParent.Foos, Mode=TwoWay}"  
                     SelectedItem="{Binding SelectedFoo, Mode=TwoWay}"
                     IsReadOnly="False" 
                     Width="1000"
                     Margin="0,10,0,0"
                     SelectionMode="Single"
                     AutoGenerateColumns="False">

Here is the XAML for the button:

<telerik:RadButton Content="Add foo"
                   x:Name="AddFooButton"
                   Margin="10,0,0,0"
                   Command="{Binding FooAddCommand}"
                   CommandParameter="{Binding ElementName=FooGrid}"
                   VerticalAlignment="Center"/>

In the View Model for the button's click event, we are doing this:

Foo f = new Foo();
f.property1 = String.Empty;
f.property2 = String.Empty;
CurrentParent.Foos.Add(f);

At the end of this function, a new foo has been added to my grid. However, it is not in edit mode. The goal is to get this new row in edit mode. Can you please advise me how to do this? Thanks for your help.

3 Answers, 1 is accepted

Sort by
0
Justin D.
Top achievements
Rank 1
answered on 24 Jan 2011, 11:16 PM
Update: The new item is always inserted as the first row in the grid. Whenever I call the BeginEdit() method, it always puts the row right below the newly added row in edit mode.
0
Maya
Telerik team
answered on 25 Jan 2011, 02:30 PM
Hi Justin D.,

You may use the built-in command - BeginInsert as demonstrated in our demo. You may take a look at our online documentation for further reference too.
 

Regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Justin D.
Top achievements
Rank 1
answered on 25 Jan 2011, 02:58 PM
Thanks for the reply. The way I got it working was by wiring up the DataLoaded event for my grid like in the code sample below. I am checking for id of 0 because I know that indicates a new row. When I find the entity with the ID of 0, I set the grid's current item to be that row and call begin edit.

private void OnFooDataLoaded(RadGridView e)
{
    for (int i = 0; i < e.Items.Count; i++)
    {
          
        Foo f = (Foo)e.Items[i];
        if (f.foo_id == 0)
        {
            e.CurrentItem = f;
            e.BeginEdit();
            break;
        }
    }
}
Tags
GridView
Asked by
Justin D.
Top achievements
Rank 1
Answers by
Justin D.
Top achievements
Rank 1
Maya
Telerik team
Share this question
or