How to update the content of DataGridView present in another form after the data is bound

你说的曾经没有我的故事 提交于 2020-04-17 20:41:05

问题


I have WordAddin & it has n forms. Of Which below are 2 forms

  1. TaskPane
  2. RibbonPane

RibbonPane has button on the click of which I need to add rows in DataGridView docked inside a TabPane contained in TaskPane.

But the data in the datagrid view(or textbox) is set to the value that is set in the TaskPane constructor. While my requirement is on ButtonClick contained in RibbonPane I need to update the content of the DataGridView(i.e., Add Rows)

 //Ribbon.cs
 public void btnSubmitClick(object sender, EventArgs e)
 {
   var obj = new TaskPane();
   obj.AddRowsToDGV(new List<Tuple<string, string>>()
   {
        new Tuple<string,string>("Google","CEO");
   });
 };


 //TaskPane.cs
  public TaskPane()
  { 
   //below reflects in UI
   dgEntitiesForReview.Rows.Add("Static","ForTesting"); 
  }

  public AddRowsToDGV(List<Tuple<string, string>> entities =null)
  { 
       //dgEntitiesForReview - DataGridView docked inside TabPage/TabControl
        if (entities!= null)
        {
            foreach (var entity in entities)
            {
                dgvEntities.Rows.Add(entity.Item1, entity.Item2);
            }
            dgEntitiesForReview.ClearSelection();
            dgEntitiesForReview.Refresh();
        }
 }

If I add a watch of quickwatch dgEntitiesForReview.Rows.Count it is updated but the same is not reflecting in UI?

Please note I checked with putting a simple textbox in place of DataGridView but the same issue.Text getting updated while debugging but not reflecting in UI

Thanks!


回答1:


In your foreach loop in AddRowsToDGV method, are you using the correct gridview? You are adding rows to dgvEntities and checking for row count on dgEntitiesForReview



来源:https://stackoverflow.com/questions/60487316/how-to-update-the-content-of-datagridview-present-in-another-form-after-the-data

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