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

[Solved] Insert (Add new Row) does not seem to work

3 Answers 268 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.
Babu Mannaravalapil
Top achievements
Rank 1
Babu Mannaravalapil asked on 10 Jan 2011, 08:57 PM
Hi

I am fairly new to both Silverlight and RadGridView for Silverlight.  I have two issues.

1. I have a RadGridView that is bound to an ObservableCollection in my ViewModel.  Things seem to work pretty much good except when the grid is populated, pressing the "Insert" key or clicking the area "Click here to add new row" does not seem to have any effect.  I have not written any code to add a new row.  But I assume, RadGridView is smart enough to insert a blank row in the grid so that the user can fill into the row.  This is mostly a simple grid except that the itemsource comes from a viewmodel Observable collection.  What do I need to do to get this thing working?  Here is my XAML code.

<UserControl x:Class="Library.Views.Contributors" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="500" d:DesignWidth="700"
        xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
        xmlns:my="clr-namespace:Library.Web.Model" xmlns:my1="clr-namespace:Library.Web.Service" xmlns:vm="clr-namespace:Library.ViewModels"
    <UserControl.Resources>
        <vm:ContributorListViewModel x:Key="ContributorsViewModel" xmlns:vm="clr-namespace:Library.ViewModels" />
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource ContributorsViewModel}}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.731*"/>
            <ColumnDefinition Width="0.269*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.8*"/>
            <RowDefinition Height="0.2*"/>
        </Grid.RowDefinitions>
        <telerik:RadGridView HorizontalAlignment="Left" Name="rgContributors" VerticalAlignment="Top" Width="Auto"
                ItemsSource="{Binding Path=Contribs}" ShowInsertRow="True" AutoGenerateColumns="False" Height="Auto" 
                Grid.Row="0" Grid.ColumnSpan="2">
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu x:Name="GridContextMenu">
                    <telerik:RadMenuItem Header="Add Row" Click="RadMenuItem_Click" />
                    <telerik:RadMenuItem Header="DeleteRow" Click="RadMenuItem_Click" />
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="ID" UniqueName="PKId" DataMemberBinding="{Binding PKId}" Width="100" IsReadOnly="True" />
                <telerik:GridViewDataColumn Header="Name" UniqueName="Name" Width="300" DataMemberBinding="{Binding Name}" />
                <telerik:GridViewDataColumn Header="Description" UniqueName="Description" Width="400" DataMemberBinding="{Binding Description}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
        <telerik:RadDataPager Height="28" HorizontalAlignment="Left" 
        Margin="8,16,0,0" Name="radDataPager1" VerticalAlignment="Top" Grid.Row="1" Grid.Column="0" d:LayoutOverrides="HorizontalAlignment, VerticalAlignment" Source="{Binding Contribs, Mode=OneWay}" PageSize="5" DisplayMode="All" />
        <StackPanel HorizontalAlignment="Left" Height="Auto" Grid.Row="1" Grid.Column="1" 
        Margin="12,16,0,0" Orientation="Horizontal" VerticalAlignment="Top" Width="Auto">
            <Button Content="Save" Height="25" Name="btnSave" Width="Auto" Margin="5" Command="{Binding Path=SaveCommand}" />
            <Button Content="Add New" Height="25" Name="btnAdd" Width="Auto" Margin="5" Command="{Binding Path=AddCommand}" />
        </StackPanel>
    </Grid>
</UserControl>

2.  I also have a RadContextMenu on this grid.  I would like to confine the visibility of this context menu only when one clicks some where in the data rows area.  In other words, I don't want the menu pop up when one clicks in the column header area or in the grouping area or anywhere else.  Just on the data rows.  How can I do this?  Thanks.

Babu.

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 11 Jan 2011, 09:11 AM
Hello Babu Mannaravalapil,

As far as I can see from the code provided, you are using RIA Services for getting the required data. In that case you need to do a couple of things for implementing the functionality of inserting/ deleting items. You may take a look at this forum thread for further reference. Another and much easier approach would be to use the RadDomainDataSource.
Considering your second requirement, you may use the RowLoaded event and attach a ContextMenu on the GridViewRow directly. For example:

private void clubsGrid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
    if (!(e.Row is GridViewHeaderRow) && !(e.Row is GridViewNewRow))
    {
        RadContextMenu rowContextMenu = new RadContextMenu();              
 
        rowContextMenu.Items.Add(new RadMenuItem() { Header = "Item1.1" });
        rowContextMenu.Items.Add(new RadMenuItem() { Header = "Item1.2" });
        RadContextMenu.SetContextMenu(e.Row, rowContextMenu);
    }
}


Kind 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
Babu Mannaravalapil
Top achievements
Rank 1
answered on 11 Jan 2011, 02:27 PM
Hello Maya,

Thanks for the quick response.  But I don't see RadDomainDatasource in my toolbox.  I even searched for it under Telerik assemblies.  It does not exist.  What am I missing here.  I am using version 2010.3.1110.1040 for Telerik.Windows.Data assembly.  If it is not yet released, what would be my other choices (other than dumping the RadGridview altogether).  I would still like to use my RIA services alongwith RadGridView.

Babu.
0
Maya
Telerik team
answered on 11 Jan 2011, 02:36 PM
Hi Babu Mannaravalapil,

The official release of the RadDomainDataSource will be with our upcoming Service Pack in a couple of days. However, you may download it from your Telerik account together with the assemblies of the Latest Internal Build. Furthermore, you may take a look at the series of blog posts demonstrating the work and implementation of the control.
The other approach would have been the one demonstrated in the forum thread.
Neither solution restrict you from using the RIA Services.
 

Best wishes,
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>>
Tags
GridView
Asked by
Babu Mannaravalapil
Top achievements
Rank 1
Answers by
Maya
Telerik team
Babu Mannaravalapil
Top achievements
Rank 1
Share this question
or