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

Problems with pasting into GridViewComboBoxColumn

5 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 14 Mar 2011, 10:26 PM
I am having problems getting paste from clipboard to work with a GridView that contains a ComboBox column.

I started from the "Classic binding to objects" Telerik demo for the ComboBox column with the addition of a RowNumber column.
If I set up the binding in code-behind (in the Page_Loaded handler) as in the demo then pasting a column of values from Excel works fine, as in the Telerik demo.

MainPageViewModel model = (MainPageViewModel)this.DataContext;
 
// Grid 1. As Telerik demo
GridViewComboBoxColumn comboColumn1 = new GridViewComboBoxColumn();
comboColumn1.DataMemberBinding = new Binding("CountryId");
comboColumn1.SelectedValueMemberPath = "Id";
comboColumn1.DisplayMemberPath = "Name";
comboColumn1.ItemsSource = model.AllCountries;
radGridView1.Columns.Add(comboColumn1);
radGridView1.ItemsSource = model.AllLocations;

However, if I set up the binding in Xaml (necessary for easy mvvm master-details I think?) then there are problems:
1. The values in the grid do not appear until the grid is clicked on.
2. If a new row is inserted (Click to add new item, select from combobox, press Enter), the values in the grid disappear until the grid is clicked on.
3. Pasting a column of values from Excel does not work. Objects are added to the collection but the value is that of the last manually selected value from one of the ComboBoxes.

<telerik:RadGridView Grid.Row="2" HorizontalAlignment="Stretch" Name="radGridView3" VerticalAlignment="Stretch" 
                     CanUserFreezeColumns="False" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False"
                     CanUserSortColumns="False" ShowColumnHeaders="True" ShowGroupPanel="False" ShowInsertRow="True"
                     RowIndicatorVisibility="Visible"
                     SelectionUnit="Cell"
                     ItemsSource="{Binding AllLocations, Mode=TwoWay}">
    <telerik:RadGridView.Columns>
        <local:RowNumberColumn Header="" Width="50" />
        <telerik:GridViewComboBoxColumn
            DataMemberBinding="{Binding CountryId, Mode=TwoWay}"
            SelectedValueMemberPath="Id"
            DisplayMemberPath="Name"
            ItemsSource="{Binding AllCountries}" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

How do I fix this and have pasting working with Xaml databinding?

5 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 14 Mar 2011, 11:16 PM
Hello Jon,

 This is very strange - it shouldn't matter if the bindings are declared in XAML or code-behind. There are two things I can think of - what would happen if you remove the Mode=TwoWay from the column binding when declaring it in XAML? Also, can you verify that the getter of the AllCountries property in your ViewModel is called correctly?

 One more thing - what do you mean when you say that the grid shows no values unless clicked on? Is it just the combo column that is empty or the whole grid? Can you add an ordinary GridViewDataColumn, bound to CountryID to see if it displays correctly? If possible, a video reproduction of the problem can help us immensely to diagnose the problem.

All the best,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Jon
Top achievements
Rank 1
answered on 14 Mar 2011, 11:52 PM
Hello Yavor,

Thank you for your reply.
Removing Mode=TwoWay from the column binding in Xaml does not change the behaviour.
The getter for AllCountries is called the expected 10 times for the 10 rows in the grid.

It is just the ComboBox column that is empty. The row numbers column is displayed.
If I add GridViewDataColumn like so:
<telerik:GridViewDataColumn DataMemberBinding="{Binding CountryId}" />
The CountryId values are correctly displayed.
The behaviour is: Press F5 to run solution, IE loads and then I get a grid with the ComboBox column blank (see picture, 2nd column). Click in the ComboBox column and the values appear.
This behaviour is worse if I add SelectionMode="Multiple" to the GridView. In this case, the values disappear again if I click in any other column, and reappear on clicking in the Combo column.

I can send you the solution (only contains this one xaml page) with a support ticket if that would help.
0
Yavor Georgiev
Telerik team
answered on 15 Mar 2011, 12:03 AM
Hi Jon,

 Yes, the solution would be very helpful in determining the cause of the problem, thank you. Please open a separate support ticket and attach it. Please use the same ticket title as the title of this thread.

Best wishes,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Jon
Top achievements
Rank 1
answered on 15 Mar 2011, 09:08 PM
Hello Yavor,

Thank you. I have opened a support ticket.
I can also send you a video of the behaviour if that would help.
Most likely I have made an elementary error somewhere!

regards,
Jon
0
Accepted
Yavor Georgiev
Telerik team
answered on 15 Mar 2011, 09:39 PM
Hi Jon,

 I just replied on the support ticket thread. In essence, the problem is that the GridViewComboBoxColumn does not inherit the DataContext of the RadGridView (your ViewModel), so you need to expose the view model as a static resource and reference it as the source when declaring the binding on the ItemsSource property in the combo box column.

Kind regards,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Jon
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Jon
Top achievements
Rank 1
Share this question
or