I have created a TableLayoutPanel that I update in the code to add/remove rows. In order to avoid flickering, I use double buffering as answered here: How to avoid flickering in TableLayoutPanel in c#.net
The problem is that, with this double buffering, the TableLayoutPannel does not always update itself when I remove some control. If I open another window and go back to the container of the TableLayoutPanel, then it is updated and work as it should. You can see a video of the problem here: TableLayoutPannel double buffering update issues.
Here is the code that run when a row is deleted:
private void FiringEvent_DeleteRequest(object sender, EventArgs e)
{
FiringEvent senderEvent = (FiringEvent)sender;
ActionLayoutPanel.Controls.Remove(senderEvent.LabelTimeControl);
ActionLayoutPanel.Controls.Remove(senderEvent.LabelActionControl);
ActionLayoutPanel.Controls.Remove(senderEvent.LabelDataControl);
ActionLayoutPanel.Controls.Remove(senderEvent.ButtonControl);
ActionLayoutPanel.RowCount--;
firingEventList.Remove(firingEvent);
updateUI();
}
private void updateUI()
{
ActionLayoutPanel.SuspendLayout();
/* Sort all event by DateTime and order them in the table */
firingEventList.Sort((x, y) => DateTime.Compare(x.eventTime, y.eventTime));
for (int i = 0; i < firingEventList.Count; i++)
{
ActionLayoutPanel.SetRow(firingEventList[i].LabelTimeControl, i + 2);
ActionLayoutPanel.SetColumn(firingEventList[i].LabelTimeControl, 0);
ActionLayoutPanel.SetRow(firingEventList[i].LabelActionControl, i + 2);
ActionLayoutPanel.SetColumn(firingEventList[i].LabelActionControl, 1);
ActionLayoutPanel.SetRow(firingEventList[i].LabelDataControl, i + 2);
ActionLayoutPanel.SetColumn(firingEventList[i].LabelDataControl, 2);
ActionLayoutPanel.SetRow(firingEventList[i].ButtonControl, i + 2);
ActionLayoutPanel.SetColumn(firingEventList[i].ButtonControl, 3);
}
ActionLayoutPanel.ResumeLayout();
}
ActionLayoutPanel is a a "DBLayoutPanel" object:
public partial class DBLayoutPanel : TableLayoutPanel
{
public DBLayoutPanel()
{
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint, true);
}
public DBLayoutPanel(IContainer container)
{
container.Add(this);
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint, true);
}
}
One solution to fix this issue is to revert the double buffering layout panel to normal TableLayoutPanel but then I have the flickering issue, so this is not really a good option.
I also tried to update the layout panel using the Update() method but it does not seem to work either. I don't understand why it update and work well when I click on another form and click on the one containing the table layout again.
P.S: The forms are handled using WeifenLuo.WinFormsUI.Docking/DockContent