hello all
i have a form that executes a search based on the users entries and returns a line of info about the certain business object ex Name of order, date, quantity ...all of this is displayed in a data grid. I would like to be able to duplicate a row. How would i be able to do this. I know i can add a button that says duplicate?
We include the notion of duplication in our object models. In our case, our primary concern and reason for not directly cloning the object was that we wanted the new instance to have its own unique identifier.
Our collection class includes a DuplicateItem method that accepts the index/identifier of the item to duplicate and does all of the work. It looks for the ICloneable interface on the item and, if found, does as described above; otherwise, we delegate to the ObjectCloner directly. Oh, we also automatically append the new item to the collection before returning it to the caller.
So, following your use-case, you would simply pass in the identifier from the row selected in the grid to the DuplicateItem on the grid's datasource (collection) and the rest would happen automatically (because a ListChanged event is raised causing the grid to refresh and show the new, duplicate item).
Hope that helps.
errrrr ok kinda sounds like greek to me i have to do some more studying...................the identifier? meaning the business object...............i want to introduce a button that will be labled duplicate item. I am assuming i will put this code in the event of this button right? if you could explain in more detail i would greatly appreciate.....i am a newbie and amatuer at csla concepts....i understand c# but not the whole framework
thanks
Presumably you are persisting your business object data to some data store such as SQL Server, Oracle, etc. As such, you have some way of uniquely identifying each object (row) so that you can retrieve the information. This value is typically used in your UI to reference the appropriate record when you want to do something on a specific item (row) like editing, deleting or copying. When you use data-binding, you will indicate this property as the key value for each item.
This is not to be confused with the index value which is the numeric location of the object within an array or list - which can also be used to identify the item you want to work with.
In our case, all of our business objects have a Guid property as their unique identifier. We overload methods on our collections that allow us to retrieve items by this value and use this property as the key when binding the collections to UI grids.
When we implement duplication, we also place a button on our form that, when clicked, obtains the key value for the selected item in the grid then calls the DuplicateItem() method on our business collection which does the rest of the work. For example, in an ASP.NET application with a GridView control bound to our business collection, we would have something like:
void DuplicateButton_Click(object sender, EventArgs e)
{
myCollection.DuplicateItem(GridView1.SelectedValue as System.Guid);
}
Hope that helps.
hey just for you to see...this is an extract of my code and what it contains
private
void button1_Click(object sender, EventArgs e){
myList.DuplicateItem(myListDataGridView.CurrentRow.DataBoundItem);
}
myList is my collection of objects. It shows up in the datagrid when you do the search.
below is the code that shows the data binding nature of my myList
private
void SortAndBindResults(myList list){
// clear previous resultsmyListBindingSource.DataSource =
null; if (list.Count > 0){
Csla.
SortedBindingList<myListInfo> sortedList = new Csla.SortedBindingList<myListInfo>(list); //sortedList.ApplySort("IsWorkCommitted", ListSortDirection.Descending);sortedList.ApplySort(
"myListId", ListSortDirection.Ascending);myListListBindingSource.DataSource = sortedList;
myListDataGridView.Focus();
}
else{
MessageBox.Show("No matching lists found", "No matching lists", MessageBoxButtons.OK);}
}
Copyright (c) Marimer LLC