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

Q1 2009 GridView breaks existing custom grid editor controls

2 Answers 71 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 16 Mar 2009, 04:44 PM
Hello,

After upgrading to the latest version (2009.1.312.35) of the WPF Grid View my custom grid editor controls have stopped working, though they worked fine with the previous version (2008.3.1217.35).  I used ideas from a forum post to create a grid editor control that allows users to type in any value they want in the combo box so they're not restricted to just the values in the list.

Now whenever I double click to edit a cell using my custom editor control, the value gets cleared and the editor does not show up.  I have to click a third time to get the editor to appear and once it does it is blank because the value got cleared.  When I debug I can see that the DataContext is always null whereas with the previous version the DataContext was always populated with the object the row was bound to.

I can reproduce this behaviour in the ForeignKey sample project from the forum post that I linked to earlier by making the following changes.

Changed this:
            comboBoxEditor.GotFocus += ((sender, e) => 
            { 
                PersonType personType = (PersonType)((Field)this.DataContext).Value; 
                comboBoxEditor.SelectedItem = (from PersonType item in comboBoxEditor.Items 
                                               where item.PersonTypeID == personType.PersonTypeID 
                                               select item).FirstOrDefault(); 
            }); 

to this:





            comboBoxEditor.GotFocus += ((sender, e) => 
            { 
                var person = DataContext as Person; 
                if (person != null && person.PersonType != null
                { 
                    comboBoxEditor.SelectedItem = (from PersonType item in comboBoxEditor.Items 
                                                   where item.PersonTypeID == person.PersonType.PersonTypeID 
                                                   select item).FirstOrDefault(); 
                } 
            }); 

Notice how when you double click on a cell in the PersonType column, the value gets cleared.  Once you click a third time the editor will appear. 

(Please note that to get this sample project to work with the latest version of the grid I also had to change the editor settings properties to be regular properties because EditorSettings seems to no longer be a dependency object.)

I hope someone can help me with this problem.

Thanks,

Joel

2 Answers, 1 is accepted

Sort by
0
Accepted
Nedyalko Nikolov
Telerik team
answered on 18 Mar 2009, 10:19 AM
Hello Joel,

I touched a little the ForeignKey example in order to work with the current release. There are some differences in:
  • CustomComboBoxEditor - some modifications to OnApplyTemplate method in order to get right ItemsSource and DisplayMemberPath properties.
  • CustomComboBoxEditorSettings - just make all properties normal .NET properties (no need from dependency properties)
  • MainWindow.xaml - Content="{Binding Data.PersonType.Name}" to Content="{Binding PersonType.Name}"
Hope this will help for now.

In the near future we plan to make special "Lookup Column" which will handle such scenarios by default.

Sincerely yours,
Nedyalko Nikolov
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
JP
Top achievements
Rank 1
answered on 18 Mar 2009, 02:23 PM
Hello Nedyalko,

Thanks for your help.  Your solution works great in the sample project.  It looks like the code snippet below (from your sample project ) is what did the trick, though I admit that I don't fully understand why.  Without that piece of the code when you double click to edit a cell, the value gets cleared, and with it, it doesn't and everything works fine.  As long as it works I guess.

        public CustomComboBoxEditor() 
        { 
            this.LostFocus += this.CustomComboBoxEditor_LostFocus; 
        } 
 
        void CustomComboBoxEditor_LostFocus(object sender, RoutedEventArgs e) 
        { 
            if (this.IsKeyboardFocusWithin) 
                e.Handled = true
        } 

Thanks again,

Joel
Tags
GridView
Asked by
JP
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
JP
Top achievements
Rank 1
Share this question
or