public SideBar() { InitializeComponent(); BackColor = backgroundColor; SqlConnection conn = new SqlConnection(); conn.ConnectionString = ConfigurationManager.AppSettings["connectionString"]; conn.Open(); string query = "SELECT sb.SIDEBAR_BUTTON_ID, sb.BUTTON_TEXT, sb.PARENT_BUTTON_ID from SIDEBAR_BUTTONS sb"; try { using (SqlCommand command = new SqlCommand(query, conn)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { SIDEBAR_BUTTON button = new SIDEBAR_BUTTON(); button.SIDEBAR_BUTTON_ID = reader.GetInt32(0); button.BUTTON_TEXT = reader.GetString(1); if (!reader.IsDBNull(2)) { button.PARENT_BUTTON = reader.GetInt32(2); } button.displayed = false; ListButtons.Add(button); } } } foreach (var button in ListButtons) { if (button.PARENT_BUTTON == 0) { SideBarButton newButton = new SideBarButton(); newButton.button1.Tag = button.SIDEBAR_BUTTON_ID; newButton.ButtonText(button.BUTTON_TEXT); newButton.button1.Click += new EventHandler(Button_Click); flowLayoutPanel1.Controls.Add(newButton); } } } catch { MessageBox.Show("Could not load sidebar buttons."); } }
public SideBar(List <SIDEBAR_BUTTON> listB, List <SIDEBAR_BUTTON> completeList) { InitializeComponent(); button1.Visible = false; BackColor = backgroundColor; ListButtons = completeList; foreach (SIDEBAR_BUTTON button in listB) { SideBarButton newButton = new SideBarButton(); newButton.button1.Tag = (button).SIDEBAR_BUTTON_ID; newButton.ButtonText((button).BUTTON_TEXT); newButton.button1.Click += new EventHandler(Button_Click); flowLayoutPanel1.Controls.Add(newButton); } }