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

Why is GridDragDropEventArgs.DraggedItems Type of IList?

4 Answers 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Doug Beard
Top achievements
Rank 1
Doug Beard asked on 28 Apr 2010, 06:54 PM
Is there a valid reason that GridDragDropEventArgs.DraggedItems is an IList instead of a GridItemCollection?
May I suggest, the items collections in handlers and helper properties alike should conform.

The fact that they don't conform present a challenge for generics and doesn't make any sense to me.

4 Answers, 1 is accepted

Sort by
0
BaiH
Top achievements
Rank 1
answered on 30 Apr 2010, 07:46 AM
Doug,
I use often this functionality in my apps and never have a problem with this. I don't see what you will gain if the collection is GridItemCollection instead of IList<GridDataItem>. What I like about this is that the generic IList is much more LinqToObjects friendly.
0
Doug Beard
Top achievements
Rank 1
answered on 26 May 2010, 06:38 PM
Posted on Apr 30, 2010 Doug,
I use often this functionality in my apps and never have a problem with this. I don't see what you will gain if the collection is GridItemCollection nstead of IList<GridDataItem>. What I like about this is that the generic IList is much more LinqToObjects friendly.



Lets say for example, you have two grids which include drag and drop functionality from one to the other.
However, you also have add and remove buttons which will also mimic the drag and drop activity, removing the item(s) from one datastore and placing it in the other.

When a button is clicked as opposed to dragging and dropping, the only option I see is to retrieve a list of selected items from one grid or the other, depending upon which button was clicked, to parse and process.

Ideally a single method which accepts a collection, will process the business logic which handles removing and adding items to the appropriate data store and rebind the grids to reflect refreshed data.

However, in the rowdrop handler the collection available in e.DraggedItems is IList and SelectedItems is GridItemCollection, which leaves only one option for the above implementation, a polymorphic method each instance accepting a different collection type, which completely defeats the purpose of a single method and lengthing the code base and thus TCO.

The only option under these circumstances is to use the generic method to process each item, which doesn't do much for reducing the business logic code in the UI.

Standardized collections across a control are paramount to reducing the cost of ownership.







0
BaiH
Top achievements
Rank 1
answered on 27 May 2010, 02:16 PM
In the general case I do agree with you. However I think that in this particular case it is not that big issue as you can have a single method with a generic IList<> parameter and cast the GridDataItemCollection to it. For example ->

    private void MyReorderMethod(IList<GridDataItem> items) 
    { 
        //do something here 
    } 

and use it like this:

         //Depending on what you are doing in the method you may change param type from IList<> to  
        //IEnumerable<> and remove the ToList call 
        MyReorderMethod(grid.SelectedItems.Cast<GridDataItem>().ToList()); 

--BH

0
Doug Beard
Top achievements
Rank 1
answered on 01 Jun 2010, 11:02 PM
Great solution, thanks for the tip.
Tags
Grid
Asked by
Doug Beard
Top achievements
Rank 1
Answers by
BaiH
Top achievements
Rank 1
Doug Beard
Top achievements
Rank 1
Share this question
or