如何在基础数据集更改时触发“面板更新控件”

时间:2015-02-25 12:25:05

标签: c# winforms user-controls

目前我有一个由'enablelocation'字段排序的数据表,因为用户可以添加项目并重新定位它们。然后,此数据表用于创建添加到面板的用户控件。

目前我们正在清除控件,然后在每次更改时重建面板(通常不会,但它仍然会发生)所以我正在寻找一种方法来更新面板上的控件变化

目前的代码是:

    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;
  }
}

0 个答案:

没有答案