问题
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