I am currently developing a C# Windows Form Application.
In the main form, there is a method for creating panels along with all the buttons and labels that are associated with it. For my case, there would be 2 types of panels, notificationPanel and notificationPanelImpt.
private Panel createNotificationPanelImpt()
{
var p = new Panel
{
BorderStyle = BorderStyle.FixedSingle,
Size = new Size(506, 100)
};
p.Controls.Add(new Button
{
Text = "Clear",
Name = "btnClear",
Location = new Point(416, 17)
});
return p;
}
I have also created a method to draw out a flowlayoutpanel to add my panels in it.
private FlowLayoutPanel createFlowLayoutPanel()
{
var nFlowPanel = new FlowLayoutPanel
{
FlowDirection = FlowDirection.TopDown,
WrapContents = false,
AutoScroll = true,
Size = new Size(530, 500),
Location = new Point(13, 145)
};
return nFlowPanel;
}
I have now added a combobox which has 3 items.
Show all, which is to show every single notification,
Important only, which is to show only the important panels,
Normal only, which is to show only all the normal panels.
How do I code it in my comboBox event handler such that it works the way I want? This is what I have done so far but i’m not sure how do I populate the panels to display what I want.
private void comboAlertType_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboAlertType.SelectedIndex == 0)
{
}
else
if (comboAlertType.SelectedIndex == 1)
{
}
else
{
}
}
Thanks!
I will suggest you to use List for this. Before adding Panels in the FlowLayoutpanel, add them in the Lists and if possible add them(normal and important) in different list. Then just run through the loop to display all the panels of a required list in the flowlayoutpanel. I have given some details in your previous query.
Hope it helps.