问题
I have WordAddin & it has n forms. Of Which below are 2 forms
- TaskPane
- 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