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

Selected row is always the last row when I select

3 Answers 311 Views
GridView
This is a migrated thread and some comments may be shown as answers.
danparker276
Top achievements
Rank 2
danparker276 asked on 13 Sep 2010, 04:24 AM

 

 

 

I'm binding data from an observable collection to the datagrid.  For some reason with this one, when click on any of the rows, the last one always gets selected instead of the row that should be.  In my code, I'm adding to the observable collection on a button click unrelated to the gridview.


<
telerik:RadGridView x:Name="rgvBillingContacts" HorizontalAlignment="Left" Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2"

 

 

 

Margin="30,10,0,0" Height="210" Width="435" SelectionMode="Single" AutoGenerateColumns="False"

 

 

 

ScrollViewer.HorizontalScrollBarVisibility="Visible"

 

 

 

IsSynchronizedWithCurrentItem="True"

 

 

 

ActionOnLostFocus="None"

 

 

 

RowIndicatorVisibility="Visible"

 

 

 

CanUserDeleteRows="True"

 

 

 

IsReadOnly="False"

 

 

 

SelectionUnit="FullRow"

 

 

 

ItemsSource="{Binding ocBillingContacts}"

 

 

 

>

 

 

 

 

<telerik:RadGridView.Columns>

 

 

 

 

<telerik:GridViewColumn>

 

 

 

 

<telerik:GridViewColumn.CellTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<telerik:RadButton Content="Delete" Command="telerik:RadGridViewCommands.Delete" CommandParameter="{Binding}" />

 

 

 

 

</DataTemplate>

 

 

 

 

</telerik:GridViewColumn.CellTemplate>

 

 

 

 

</telerik:GridViewColumn>

 

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding AddressId}" IsReadOnly="True" IsVisible="False" Header="key" />

 

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" IsReadOnly="True" Width="150" Header="Name" />

 

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding Title}" IsReadOnly="True" Width="100" Header="Title" />

 

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding CompanyName}" IsReadOnly="True" Width="100" Header="Company" />

 

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding Address1}" IsReadOnly="True" Width="100" Header="Address1" />

 

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding Address2}" IsReadOnly="True" Width="100" Header="Address2" />

 

 

 

 

</telerik:RadGridView.Columns>

 

 

 

 

</telerik:RadGridView>

 

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 14 Sep 2010, 01:14 PM
Hi Dan,

Could you please send us a sample application that demonstrates this issue?


Regards,
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
danparker276
Top achievements
Rank 2
answered on 14 Sep 2010, 07:38 PM

Ok when making the sample, I found that I can't make the class that I'm adding to my observable collection global.


    public partial class Screen9 : Page 
    
    
        ObservableCollection<BillingContacts> ocBillingContacts = new ObservableCollection<BillingContacts>(); 
    
    
        BillingContacts currentCCAdd = new BillingContacts(); //THIS WILL FAIL UP HERE 
    
... Init... 
    
        private void btCC_Click(object sender, RoutedEventArgs e) 
        
           BillingContacts currentCCAdd = new BillingContacts(); //Correct SPOT!! 
           //Fillup currentCCAdd  
           ... 
            ocBillingContacts.Add(currentCCAdd); 
        
0
Milan
Telerik team
answered on 17 Sep 2010, 08:55 AM
Hi Dan,

Yes, you will have to create a different instance every time you want to add a new item.


All the best,
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
Tags
GridView
Asked by
danparker276
Top achievements
Rank 2
Answers by
Milan
Telerik team
danparker276
Top achievements
Rank 2
Share this question
or