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

Double rows after adding a NewRow by code (ria) with Required Values

5 Answers 71 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 12 May 2010, 07:36 AM

Hi

I’m testing the GridView and have a problem with adding new rows. I get a new row twice in the grid when I click again the AddNew button.

 

Here is my code:


        <telerik:RadGridView ItemsSource="{Binding ElementName=TQualityDomainDataSource, Path=Data}"   
                                     Name="DG"   
                                     AutoGenerateColumns="False"    
                                     Margin="0,100,0,20"   
                                     IsBusy="{Binding IsBusy}"   
                                     AlternationCount="4" ColumnWidth="80">  
 
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn x:Name="qua_emissionColumn"     DataMemberBinding="{Binding Path=qua_emission}"   Header="Emission"  /> 
 
                <telerik:GridViewComboBoxColumn x:Name="qua_ene_idComboColumn" Header="Energieträger" Width="200"   
                                                        SortMemberPath="tEnergie.ene_name" 
                                                        ItemsSource="{Binding Source={StaticResource ENERGIE}, Path=Data}"   
                                                        DisplayMemberPath="ene_name"   
                                                        SelectedValueMemberPath="ene_id"   
                                                        DataMemberBinding="{Binding qua_ene_id, Mode=TwoWay}"  /> 
 
                <telerik:GridViewDataColumn x:Name="Min_CH4Column"          DataMemberBinding="{Binding Path=qua_O_CH4}"        Header="CH4 o"        DataFormatString="{}{0:N4}" TextAlignment="Right" /> 
 
            </telerik:RadGridView.Columns> 
 
        </telerik:RadGridView> 
 
 
        <riaControls:DomainDataSource AutoLoad="False"   
                                      d:DesignData="{d:DesignInstance my:tQuality, CreateList=true}" Height="0"   
                                      Name="TQualityDomainDataSource"   
                                      QueryName="GetTQualityArchivQuery" Width="0">  
            <riaControls:DomainDataSource.DomainContext> 
                <my:KeefDS /> 
            </riaControls:DomainDataSource.DomainContext> 
            <riaControls:DomainDataSource.QueryParameters> 
                <riaControls:Parameter ParameterName="ArcID" Value="{Binding ElementName=ArcIDTextBox, Path=Text}" /> 
            </riaControls:DomainDataSource.QueryParameters> 
        </riaControls:DomainDataSource> 
 
    Private Sub BtNew_Click(ByVal sender As System.ObjectByVal e As System.Windows.RoutedEventArgs) Handles BtNew.Click  
        DG.BeginInsert()  
    End Sub 
 
 
 
    Private Sub DG_AddingNewDataItem(ByVal sender As ObjectByVal e As Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs) Handles DG.AddingNewDataItem  
        Try 
            Dim newTM As New tQuality  
            With newTM  
                .qua_ene_id = 5  
                .qua_id = Guid.NewGuid  
                .qua_arc_id = CInt(Arc_idComboBox.SelectedValue)  
                .qua_EmissionsKlasse = 0  
                .qua_emission = _LastEmission  
            End With 
            e.NewObject = newTM  
            TQualityDomainDataSource.DataView.Add(e.NewObject)  
 
        Catch ex As Exception  
            System.Windows.MessageBox.Show(ex.Message + vbCrLf + vbCrLf + ex.ToString, "Add Error", System.Windows.MessageBoxButton.OK)  
        End Try 
    End Sub 
 

Thanks for help.
Peter

5 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 13 May 2010, 01:52 PM
Hello Peter Andres,

There is no need to call

TQualityDomainDataSource.DataView.Add(e.NewObject)

in the event handler for AddingNewDataItem. Duplicate items should not appear once this line is removed.


Greetings,
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
Peter
Top achievements
Rank 1
answered on 13 May 2010, 04:00 PM
Thanks for the answer.
If I remove this line, I dont get a new row. nothing happens to the grid.
0
Nedyalko Nikolov
Telerik team
answered on 17 May 2010, 09:53 AM
Hi Peter Andres,

Generally you don't need to add item directly to the underlying data source within AddingNewDataItem event handler. This event is designed as an option to add custom instance of your business object (and when your business object does not have default (parameter less constructor)).
When DomainDataSource is used you have to ensure that all changes are submitted to the database accordingly. You can do that inside RadGridView.RowEditEnded event handler. I'm attaching a sample application that demonstrates this approach. The example works with Northwind sample database and requires SQL server EXPRESS, if you have another instance of SQL server you have to modify "web.config" file.

Let me know how this works on your end.

Regards,
Nedyalko Nikolov
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
Peter
Top achievements
Rank 1
answered on 17 May 2010, 01:29 PM
Hi Nedyalko Nikolov

Thanks a lot for your help. I have still some problems. As long as I don't do something in the

DG_AddingNewDataItem event, everything goes well. But I need some initial values for the new record. If I create them with

            Dim newTM As New tQuality   
            With newTM  
                .qua_ene_id = x  
                .qua_id = Guid.NewGuid  
                .qua_arc_id = MyMainPage.GetArchivID  
                .qua_EmissionsKlasse = 0  
                .qua_emission = _LastEmission  
            End With 
 
            e.NewObject = newTM 
in the event procedure, I don't get the new record at all. If I use the AddNew method to get a new record, I have the old behaviour: double entries
            Dim ttt As IEditableCollectionView = CType(TQualityDomainDataSource.Data, IEditableCollectionView)  
            Dim newTM = CType(ttt.AddNew, tQuality)  
            ' Dim newTM As New tQuality   
 
Best regards,
Peter
0
Nedyalko Nikolov
Telerik team
answered on 20 May 2010, 08:26 PM
Hello Peter Andres,

Sorry for the late reply. You can set RadGridView.ShowInsertRow to true in order to use special UI to add new item. When this "Insert row" is used RadGridView handles the case when underlying data source is an IEditableCollectionView. Let me know if this doesn't help.

All the best,
Nedyalko Nikolov
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.
Tags
GridView
Asked by
Peter
Top achievements
Rank 1
Answers by
Milan
Telerik team
Peter
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or