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

Pasting onto GridViewComboBoxColumn - Issue

4 Answers 201 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 25 Aug 2010, 07:38 PM

Hi,

Using Q2 2010 SP1 on XP Pro with C# .NET 3.5

I'm noticing that when I copy values from a comboBox where the comboBox is setup like

GridViewComboBoxColumn combo= ((GridViewComboBoxColumn)gridView.Columns["myColumn"]);
combo.ItemsSource = GetGrouping(); //returns List<Group> which just contains GroupName, and GroupId referenced below
combo.DataMemberBinding = new Binding("GroupId");
combo.DisplayMemberPath = "GroupName";
combo.SelectedValueMemberPath = "GroupId";

if I copy that onto the clipboard I get the display value.. but whenever I paste.. the value doesn't paste properly onto the GridViewComboBox because it's expecting the Id value from the paste.  I verified this by changing the paste value inside the

PastingCellClipboardContent event.  When I changed the "Name" value to  a corresponding "Id" value the paste was "visually succesful" meaning the display value on the datagrid changed to match the value I copied from the originiating ComboBox cell. 


There doesn't seem to be any other option when copying (and I don't really think there should be.. because that would break pasting to external applications)... but I'm wondering if I've just setup the column improperly or is this just the way this control works?

Thanks for any assistance.

4 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 25 Aug 2010, 08:43 PM
private void GridView_PastingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e)
        {
            GridViewComboBoxColumn comboBox = (e.Cell.Column as GridViewComboBoxColumn);
            if (comboBox != null)
            {
                foreach(object item in comboBox.ItemsSource)
                {
  
                    PropertyInfo pi = Utility.GetProperty(item.GetType(), comboBox.DisplayMemberPath);
  
                    object itemValue = Utility.GetPropertyValue(pi, item);
  
                    if (itemValue.ToString() == e.Value.ToString())
                    {
                        PropertyInfo valueProperty = Utility.GetProperty(item.GetType(), comboBox.SelectedValueMemberPath);
  
                        object valuePropertyValue = Utility.GetPropertyValue(valueProperty, item);
  
                        e.Value = valuePropertyValue;
                    }
  
                }
                  
}
        public  static PropertyInfo GetProperty(Type objectType, string propertyName)
        {
            return objectType.GetProperty(propertyName);
        }
  
        public static object GetPropertyValue(PropertyInfo property, object objectToQuery)
        {
            if (property == null || objectToQuery == null)
                return null;
  
            return property.GetValue(objectToQuery, null);
        }
            }

This is a generic method that accomplishes what I needed.  Hopefully some of you will find it useful... the methods called via "Utility." are listed below the event handler above.


0
Yavor Georgiev
Telerik team
answered on 27 Aug 2010, 10:11 AM
Hello Jason,

 Thank you for spotting this issue. I have awarded you Telerik points for your cooperation.

 We have rectified the behavior of the GridViewComboBox column in this scenario, so that you shouldn't need to handle PastingCellClipboardContent in this particular case. You will be able to find the fix in this week's Internal Build, which should be online by the end of the day.

Regards,
Yavor Georgiev
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
Jason
Top achievements
Rank 1
answered on 01 Sep 2010, 04:25 PM
The one thing that the current build doesn't handle that my hacked together version did handle was when the displayMemberPath of a comboBox had values shared between 2 different boxes

example

box 1  = [a,b,c]
box 2 = [a,y,z]

I could copy the display member "a"  from box 1 and successfully paste to box 2.  Because it would search the itemsource of the destination column for any matches by displaymemberPath name and set it there.  I guess that's dangerous because nothing is preventing you from having 2 of the same displayMemberPath.

Any ideas on this?
0
Yavor Georgiev
Telerik team
answered on 02 Sep 2010, 10:18 AM
Hello Jason,

 The current implementation re-uses some code from RadComboBox. Pasting now works in the following way: get the pasted value and trick a dummy RadComboBox (which is configured with the properties from the ComboBoxColumn) into thinking you changed its Text property to the value that is pasted. If the value is valid for that RadComboBox, it's SelectedValue property changed to the object we need, which we then assign to the property behind the ComboBoxColumn's DataMemberBinding.

If you'd like to open a support ticket and send an example project demonstrating your scenario in more detail, I'll do my best to study it and incorporate the correct solution in our copy/paste mechanism so that it happens seamlessly for you.

Regards,
Yavor Georgiev
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
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Share this question
or