private void BuildList() { DataGridViewSelectedRowCollection selectedRows = this.dataGridViewVDIs.SelectedRows; int firstDisplayedScrollingRowIndex = this.dataGridViewVDIs.FirstDisplayedScrollingRowIndex; this.dataGridViewVDIs.SuspendLayout(); try { this.dataGridViewVDIs.Rows.Clear(); if (this.sr == null) { return; } List <VDI> list = this.sr.Connection.ResolveAll <VDI>(this.sr.VDIs); this.storageLinkVolumeColumn.Visible = list.Find(v => v.sm_config.ContainsKey("SVID")) != null; foreach (VDI vdi in list) { if (vdi.is_a_snapshot) { bool isNotShow = vdi.GetVMs().Where(vm => vm.Show(true)).Any(vm => vm.is_a_snapshot && vm.other_config.ContainsKey("halsign_snapshot")); if (isNotShow) { continue; } } if (vdi.Show(XenAdmin.Properties.Settings.Default.ShowHiddenVMs) && !vdi.IsAnIntermediateStorageMotionSnapshot) { VDIRow dataGridViewRow = new VDIRow(vdi, this.storageLinkVolumeColumn.Visible); this.dataGridViewVDIs.Rows.Add(dataGridViewRow); } } IEnumerable <VDI> source = from row in selectedRows.Cast <VDIRow>() select row.VDI; foreach (VDIRow row2 in (IEnumerable)this.dataGridViewVDIs.Rows) { row2.Selected = source.Contains <VDI>(row2.VDI); } } finally { if ((this.dataGridViewVDIs.SortedColumn != null) && (this.dataGridViewVDIs.SortOrder != SortOrder.None)) { this.dataGridViewVDIs.Sort(this.dataGridViewVDIs.SortedColumn, (this.dataGridViewVDIs.SortOrder == SortOrder.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending); } this.dataGridViewVDIs.ResumeLayout(); } if (this.dataGridViewVDIs.Rows.Count > 0) { this.dataGridViewVDIs.FirstDisplayedScrollingRowIndex = ((firstDisplayedScrollingRowIndex < 0) || (firstDisplayedScrollingRowIndex >= this.dataGridViewVDIs.Rows.Count)) ? 0 : firstDisplayedScrollingRowIndex; } this.RefreshButtons(); }
private void RefreshDataGridView(VDIsData data) { dataGridViewVDIs.SuspendLayout(); try { storageLinkVolumeColumn.Visible = data.ShowStorageLink; // Update existing rows foreach (var vdiRow in data.VdiRowsToUpdate) { vdiRow.RefreshRowDetails(data.ShowStorageLink); } // Remove rows for deleted VDIs foreach (var vdiRow in data.VdiRowsToRemove) { dataGridViewVDIs.Rows.RemoveAt(vdiRow.Index); } // Add rows for new VDIs foreach (var vdi in data.VdisToAdd) { VDIRow newRow = new VDIRow(vdi, data.ShowStorageLink); dataGridViewVDIs.Rows.Add(newRow); } } finally { if (dataGridViewVDIs.SortedColumn != null && dataGridViewVDIs.SortOrder != SortOrder.None) { dataGridViewVDIs.Sort(dataGridViewVDIs.SortedColumn, dataGridViewVDIs.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending); } dataGridViewVDIs.ResumeLayout(); } RefreshButtons(); }
private void RefreshDataGridView(VDIsData data) { dataGridViewVDIs.SuspendLayout(); try { storageLinkVolumeColumn.Visible = data.ShowStorageLink; // Update existing rows foreach (var vdiRow in data.VdiRowsToUpdate) { vdiRow.RefreshRowDetails(data.ShowStorageLink); } // Remove rows for deleted VDIs foreach (var vdiRow in data.VdiRowsToRemove) { dataGridViewVDIs.Rows.RemoveAt(vdiRow.Index); } // Add rows for new VDIs foreach (var vdi in data.VdisToAdd) { VDIRow newRow = new VDIRow(vdi, data.ShowStorageLink); dataGridViewVDIs.Rows.Add(newRow); } } finally { if (dataGridViewVDIs.SortedColumn != null && dataGridViewVDIs.SortOrder != SortOrder.None) dataGridViewVDIs.Sort(dataGridViewVDIs.SortedColumn, dataGridViewVDIs.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending); dataGridViewVDIs.ResumeLayout(); } RefreshButtons(); }
private void BuildList() { //Save the selection DataGridViewSelectedRowCollection selectedItems = dataGridViewVDIs.SelectedRows; int firstrowDisplayed = dataGridViewVDIs.FirstDisplayedScrollingRowIndex; dataGridViewVDIs.SuspendLayout(); try { dataGridViewVDIs.Rows.Clear(); if (sr == null) return; List<VDI> vdis = sr.Connection.ResolveAll(sr.VDIs); storageLinkVolumeColumn.Visible = vdis.Find(v => v.sm_config.ContainsKey("SVID")) != null; foreach (VDI vdi in vdis) { if (!vdi.Show(Properties.Settings.Default.ShowHiddenVMs)) continue; if (vdi.IsAnIntermediateStorageMotionSnapshot) continue; VDIRow newRow = new VDIRow(vdi, storageLinkVolumeColumn.Visible); dataGridViewVDIs.Rows.Add(newRow); } IEnumerable<VDI> selectedVDIs = from VDIRow row in selectedItems select row.VDI; foreach (VDIRow row in dataGridViewVDIs.Rows) { row.Selected = selectedVDIs.Contains(row.VDI); } } finally { if (dataGridViewVDIs.SortedColumn != null && dataGridViewVDIs.SortOrder != SortOrder.None) dataGridViewVDIs.Sort(dataGridViewVDIs.SortedColumn, dataGridViewVDIs.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending); dataGridViewVDIs.ResumeLayout(); } if (dataGridViewVDIs.Rows.Count > 0) dataGridViewVDIs.FirstDisplayedScrollingRowIndex = (firstrowDisplayed < 0 || firstrowDisplayed >= dataGridViewVDIs.Rows.Count) ? 0 : firstrowDisplayed; RefreshButtons(); }