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

Binding to GridView datasource changes data on previously selected item

3 Answers 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 03 Mar 2009, 03:06 PM
My GridView's ItemsSource is set to {Binding}, which binds to it's parent's DataContext.  I also have a couple comboboxes and some checkboxes that are bound to properties on the items in this DataContext.

When I make changes in the comboboxes and checkboxes, the changes are reflected on the previously selected item in the GridView rather than the currently selected item.  Why would this happen?

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 04 Mar 2009, 01:28 PM
Hi Bob,
Can you please give me some more details so I can reproduce the problem here?
It would be helpful for me to know more about the type of the datasource you use and the code you use to update that source. 
Ideally a project or a piece of code  (codebehind and/or XAML ) will let me investigate and provide you with a solution or a  workaround . If it happens to be a bug in the grid we will be having a new release in a few days so we can include a bugfix if necessary.

Greetings,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Bob
Top achievements
Rank 1
answered on 04 Mar 2009, 07:58 PM
Here's a shortened sample of my XAML:

<Grid Margin="5" x:Name="NotesGrid">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <telerik:RadGridView x:Name="NotesGridView" Height="200" Grid.Row="0" ItemsSource="{Binding}" />
    <TextBox Text="{Binding Path=FieldName}">
</Grid>

In the constructor for this XAML's containing window, the DataContext of NotesGrid is set to an ObservableCollection of type Note.  Shouldn't be any problems with the collection.  It's a property on the Window.

The Note class subclasses DependencyObject and it contains DependencyProperties and their Property accessors.  For instance:

public static readonly DependencyProperty FieldNameProperty =
    DependencyProperty.Register("FieldName", typeof(string), typeof(Note), new UIPropertyMetadata(null));

public string FieldName
{
    get { return (string)GetValue(FieldNameProperty); }
    set { SetValue(FieldNameProperty, value); }
}

We're using RadGridView in 2-3 other places in our application, but none of the locations allows the user to make changes.  Those instances simply display data.

I've used ListBoxes before to display data while allowing the user to use TextBoxes, ComboBoxes, etc to change data, but have never used a RadGridView to accomplish this.
0
Pavel Pavlov
Telerik team
answered on 05 Mar 2009, 01:46 PM
Hi Bob,

I have tried to resemble your case scenario.
Attached is a small sample. It demonstrates a way to have external text box to edit the selected item in the grid. Any changes made in the textbox would reflect into the selected item in the RadGridView.

Please let me know if you need any further assistance.

Best wishes,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Bob
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Bob
Top achievements
Rank 1
Share this question
or