currently I have a datatable that is ordered by an 'enablelocation' field as a user can add items and reposition them. this datatable is then used to create user controls that are added to a panel.
Currently we are clearing the controls and then rebuilding the panel each time there is a change (whih isn't often, but it still happens) so I am looking for a way of updating the controls on the panel when there is a change.
the current code is this:
private void UpdateCats(int formid) {
//update dataset
cassess.Tables["CaseAssessDefCats"].Clear();
DataTable tcats = Requests.SQLGen.ProcessSQLCommand(gobj, null, "select id,name,shownohistory, case when EnableLocation is null then 1 else EnableLocation end as EnableLocation,FormID from CaseAssessDefCats where EnableLocation >= 0 and FormID = " + formid + " order by EnableLocation, Name", false, true);
if (tcats != null && tcats.Rows.Count > 0) {
tcats.TableName = "CaseAssessDefCats";
cassess.Merge(tcats);
}
//end update dataset
try {
if (_processing) { //check if update is running
return;
}
ClearAssessment(); //removes all the controls
_processing = true;
panMain.Refresh();
panMain.SuspendLayout();
//loop through datatable, re-adding them as controls
for (int a = cassess.CaseAssessDefCats.Rows.Count - 1; a >= 0; a--) {
trow = cassess.CaseAssessDefCats[a];
tcat = new CaseAssessDefCat(cassess, trow, gobj);
tcat.Tag = trow.ID;
tcat.catUp += new EventHandler(CatUp);
tcat.catDown += new EventHandler(CatDown);
tcat.catDelete += new EventHandler(CatDelete);
tcat.catEnter += new EventHandler(CatEnter);
tcat.catLeave += new EventHandler(CatLeave);
tcat.catEdit += new EventHandler(CatEdit);
tcat.catNew += new EventHandler(CatNew);
panMain.Controls.Add(tcat);
tcat.Dock = DockStyle.Top;
}
panMain.ResumeLayout();
_processing = false;
return;
} catch {
panMain.ResumeLayout();
_processing = false;
return;
}
}