Hey guys,
I bound my grid to a list of objects ( List<BO> ) and I was wondering how I can implement copy and paste functionality so the grid copies and pastes a record and the underlying object.
I can see it works great with cell data, but can it copy whole records and paste (add) objects in the underlying datasource?
I currently have several lines of code to accomplish this to work with Ctrl C and Ctrl V and cancel the BeforeMultiCellOperation event. However I'm running into some issues since I also would like to copy back and forth from Excel so I was wondering what's the best way to copy whole rows with an object list as the datasource.
Thanks !
ok thanks.
Hi,
I don't think the grid will do this for you automatically. You can paste only onto rows that already exist in the grid. If you copy two rows, you would have to select 2 rows in order to paste them, and since there is only one TemplateAddRow in the grid, you could only add one row at a time.
Hey Mike thanks for replying, I need to explain my self better since we are talking about two different things.
I have an object:
class TestObject
{
public string Property1
{get;set;}
public int Property2
}
And I'm binding my grid to an instance of List<TestObject>
So the grid has two columns, each one displays a property of my object.
If I highlight one cell and try to copy it to another cell, it works just fine.
However, say that my List<TestObject> has 3 instances of TestObject, if I highlight 2 entire rows, press Ctrl + C to copy them and then Ctrl + V to paste them, I would expect the grid to have now 5 rows (3 original rows + 2 more that were just copied and pasted) and also I would expect List<TestObject> to have 5 instances now.
Is this a built-in functionality? I was able to code it myself but it is becoming hard to maintain
Thanks
I'm not sure I understand the question, but the built-in support for copy and paste in the grid has to convert everything into strings and then it just fills in the cell in the grid with those strings just as though the user typed it in.
If you have a cell in the grid that is an object, then the cell will display the ToString method of that object and the field will not be editable by the user. The grid would not know what to do if the user typed in a string into that field, since it would not know how to create an instance of the object or what other properties on the object would need to be set.
So if you need to copy object instances from one cell to another, the grid can't really help you with that.