Updated rows in DataGridView not reflecting in UI C# WinForms

无人久伴 提交于 2020-03-04 23:18:28

问题


I have a WinForms application & it has DataGridView.

It has a form TaskPane. If I add any new row in the constructor it adds while at any other place it doesn't.

  public TaskPane(List<Tuple<string, string>> entities =null)
    {
        InitializeComponent();

        tabTextForReview.BorderStyle = BorderStyle.FixedSingle;
        dgEntitiesForReview.Rows.Add("StaticKey", "StaticContent");

        if (entities!= null)
        {
            foreach (var entity in entities)
            {
                dgEntitiesForReview.Rows.Add(entity.Item1, entity.Item2);
                // tried with ->dgEntitiesForReview.Rows.Add("DynamicKey", "DynamicContent");
            }
            dgEntitiesForReview.ClearSelection();
            dgEntitiesForReview.Refresh();

        }
 }

When the form is loaded for at first, the StaticKey row is added & reflects in UI. While when updating the rows at any other instance (or second time or from any method) the rows are not reflected in UI.

Second Instance Call(on button click)

public void btnSubmitClick(object sender, EventArgs e)
{
   TaskPane tp = new TaskPane(new List<Tuple<string,string>>(){
      new Tuple<string,string>("DyanmicKey", "DynamicContent");
  });
}

While if I check in QuickWatch window I can see the rows count is updated.

Please note the DataGridView has "Adding/Editing/Deleting Enabled"

How to reflect this in UI?

Thanks!

来源:https://stackoverflow.com/questions/60449603/updated-rows-in-datagridview-not-reflecting-in-ui-c-sharp-winforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!