dimanche 8 mars 2015

Merge DataGridView binded Bindinglist and freshly retrieved Bindinglist with updates


Vote count:

0




I have tasks bindinglist binded to DataGridView. which I currently refresh from server using



public static bool ReadTasks(ref SortableBindingList<ClientTask> tasks, ref RestClient rClient, out IRestResponse rResponse)
{
JsonDeserializer rJSONDeserializer = new RestSharp.Deserializers.JsonDeserializer();
if (ReadObject(ref rClient, "tasks", "", out rResponse))
{
tasks = rJSONDeserializer.Deserialize<SortableBindingList<ClientTask>>(rResponse);
return true;
}
else
{
return false;
}
}


This causes the original tasks to be overwritten thus losing its binding. So I tried the following



if (tasks == null) tasks = new SortableBindingList<ClientTask>();
tasks.Clear();
foreach (ClientTask item in JSONDeserilizer.Deserialize<SortableBindingList<ClientTask>>(rResponse))
{
tasks.Add(item);
}


This updates my grid properly but I lose the user selection. So is there anyway I can merge the new and old tasks. By merge I mean the deserialized one should overwrite differences on old tasks list but maintain the binding/Sort order etc. The deserialized list can contain new tasks,updated tasks or might have some tasks deleted.


the Task Class is as follows



public class ClientTask : Task
{
public string taskName
{
get { return this.name + " - " + this.title; }
}
public string DeveloperName
{
get { return Globals.People.Find(x => x.id == this.developer_id).name; }
}
public string ReviewerName
{
get { return Globals.People.Find(x => x.id == this.reviewer_id).name; }
}
}

public class Task
{
public Task()
{
open_date = DateTime.Now.AddDays(0*7);
analysis_date = DateTime.Now.AddDays(1*7);
review_date = DateTime.Now.AddDays(1*7);
correction_date = DateTime.Now.AddDays(1*7);
promotion_date = DateTime.Now.AddDays(1*7);
collection_date = DateTime.Now.AddDays(2*7);
closed_date = DateTime.Now.AddDays(3*7);
developer_id = Globals.People.First().id;
reviewer_id = Globals.People.First().id;
}
public int id { get; set; }
public int developer_id { get; set; }
public int reviewer_id { get; set; }
public string name { get; set; }
public eTaskStatus task_status { get; set; }
public eBugType bug_type { get; set; }
public string title { get; set; }
public string internal_object_id { get; set; }
public bool approved { get; set; }
public bool is_bug { get; set; }
public string description { get; set; }
public string analysis { get; set; }
public string review { get; set; }
public int comments_count { get; set; }
public int documents_count { get; set; }
public DateTime open_date { get; set; }
public DateTime analysis_date { get; set; }
public DateTime review_date { get; set; }
public DateTime correction_date { get; set; }
public DateTime promotion_date { get; set; }
public DateTime collection_date { get; set; }
public DateTime closed_date { get; set; }
public DateTime target_date { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
public List<Document> documents { get; set; }
}


When retrieving the tasks list from the server only following attributes are retrieved :id,:name,:task_status,:is_bug,:title,:bug_type,:target_date,:created_at,:updated_at,:approved,:developer_id


I also found this Reconciling a new BindingList into a master BindingList using LINQ but it went over my head.


More Info:

SortableBindingList

RestSharp Deserialization



asked 25 secs ago

AEonAX

106






Merge DataGridView binded Bindinglist and freshly retrieved Bindinglist with updates

Aucun commentaire:

Enregistrer un commentaire