private void _comboBox_Server_SelectionChangeCommitted(object sender, EventArgs e) { int serverId = (int)_comboBox_Server.SelectedValue; string selectedSnapshot1 = string.Empty; string selectedSnapshot2 = string.Empty; if (m_ServerId == serverId) { selectedSnapshot1 = _comboBox_Snapshot1.Text; selectedSnapshot2 = _comboBox_Snapshot2.Text; m_ServerId = serverId; } m_ServerId = serverId; // load the snapshot list for the selected server m_SnapshotList = Sql.Snapshot.LoadSnapshots(_comboBox_Server.Text); // Clear the snapshots for any previous server List <MyComboBoxItem> li1 = new List <MyComboBoxItem>(); List <MyComboBoxItem> li2 = new List <MyComboBoxItem>(); li2.Add(new MyComboBoxItem(ComboTextChooseSnapshot, 0)); foreach (Snapshot snapshot in m_SnapshotList) { if (snapshot.HasValidPermissions) { li1.Add(new MyComboBoxItem(snapshot.SnapshotName, snapshot.SnapshotId)); li2.Add(new MyComboBoxItem(snapshot.SnapshotName, snapshot.SnapshotId)); } } _comboBox_Snapshot1.DisplayMember = "Label"; _comboBox_Snapshot1.ValueMember = "Index"; _comboBox_Snapshot1.DataSource = li1; _comboBox_Snapshot1.Text = selectedSnapshot1; _comboBox_Snapshot2.DisplayMember = "Label"; _comboBox_Snapshot2.ValueMember = "Index"; _comboBox_Snapshot2.DataSource = li2; _comboBox_Snapshot2.Text = selectedSnapshot2; _comboBox_Snapshot1.Enabled = _comboBox_Snapshot2.Enabled = m_SnapshotList.Count > 0; checkSelections(); }
private void _comboBox_Snapshot_DropDown(object sender, EventArgs e) { // Used for both snapshot combo boxes ComboBox comboBox = (ComboBox)sender; //Keep the last selection for the user string selection = comboBox.Text; List <MyComboBoxItem> li = new List <MyComboBoxItem>(); if (((List <MyComboBoxItem>)comboBox.DataSource).Count > 0 && ((List <MyComboBoxItem>)comboBox.DataSource)[0].Index == 0) { li.Add(new MyComboBoxItem(ComboTextChooseSnapshot, 0)); } //comboBox.Items.Clear(); Sql.RegisteredServer server = Program.gController.Repository.RegisteredServers.Find(m_ServerId); if (server != null) { // load the snapshot list for the selected server m_SnapshotList = Sql.Snapshot.LoadSnapshots(_comboBox_Server.Text); bool selectionFound = false; foreach (Snapshot snapshot in m_SnapshotList) { if (snapshot.HasValidPermissions) { li.Add(new MyComboBoxItem(snapshot.SnapshotName, snapshot.SnapshotId)); if (snapshot.SnapshotName == selection) { selectionFound = true; } } } comboBox.DisplayMember = "Label"; comboBox.ValueMember = "Index"; comboBox.DataSource = li; if (selectionFound) { comboBox.Text = selection; } } }