public DataGridViewMovedRows(DataGridViewSelectedRowCollection rows, DataGridView source) { if (rows == null) { throw new ArgumentNullException(nameof(rows)); } modifiedRows = rows.Cast <DataGridViewRow>().OrderBy(x => x.Index).ToArray(); SourceRows = new ReadOnlyCollection <DataGridViewRow>((DataGridViewRow[])modifiedRows.Clone()); Source = source; }
public static List <DataRow> ToDataRows(this DataGridViewSelectedRowCollection Rows) { if (Rows == null || Rows.Count == 0) { return(null); } return(Rows.Cast <DataGridViewRow>() .Where(x => x.DataBoundItem is DataRowView) .Select(x => ((DataRowView)(x.DataBoundItem)).Row).ToList()); }
/// <summary> /// 获取DataGridView中的选中行或当前行 /// </summary> /// <param name="gridView">DataGridView对象</param> /// <returns>返回List</returns> public static List <DataGridViewRow> GetDataGridViewSelectedRows(this DataGridView gridView) { List <DataGridViewRow> list; DataGridViewSelectedRowCollection rows = gridView.SelectedRows; list = rows == null ? new List <DataGridViewRow>() : rows.Cast <DataGridViewRow>().ToList(); list.Add(gridView.CurrentRow); return(list); }
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 TasksListDataGrid_SelectionChanged(object sender, EventArgs e) { DataGridViewSelectedRowCollection selecetedRows = TasksListDataGrid.SelectedRows; if (selecetedRows.Count > 0) { DataGridViewRow selectedRow = selecetedRows .Cast <DataGridViewRow>() .First(); taskToBeRemoved = GetTaskFromRow(selectedRow); this.TaskNameToRemoveL.Text = taskToBeRemoved.title; } }
/// <summary> /// Gets the specified <paramref name="selection"/> ordered by its index. /// </summary> /// <param name="selection">The <see cref="DataGridViewSelectedRowCollection"/> to order.</param> /// <returns>The specified <paramref name="selection"/> ordered by its index.</returns> public static IEnumerable <DataGridViewRow> OrderByIndex(this DataGridViewSelectedRowCollection selection) { return(selection.Cast <DataGridViewRow>().OrderBy(row => row.Index)); }
public static IEnumerable <DataGridViewRow> AsEnumerable(this DataGridViewSelectedRowCollection selrows) => selrows.Cast <DataGridViewRow>();
public static DataGridViewRow TopmostRow(this DataGridViewSelectedRowCollection selectedRows) { return(selectedRows.Cast <DataGridViewRow>().OrderBy(r => r.Index).First()); }
private void deleteBtn_Click(object sender, EventArgs e) { DataGridView dgv = (DataGridView)this.tabControl1.SelectedTab.Controls[0]; DataGridViewSelectedRowCollection dgvsrc = dgv.SelectedRows; if (dgvsrc.Count == 0) { MessageBox.Show("You have first to select cookie that you want to delete"); } else { string browserName = ((KeyValuePair <string, string>) this.comboBox1.SelectedItem).Key; string profileName = this.tabControl1.SelectedTab.Text; if (browserName == "all") { int browserNameColumnIndex = dgv.Columns[browserNameColumnName].Index; foreach (string eachBrowserName in this.webBrowsers.Keys) { if (eachBrowserName != "all") { IEnumerable <DataGridViewRow> rowsWithCookiesOfCurrentBrowserToDelete = dgvsrc.Cast <DataGridViewRow>().Where(x => ((Dictionary <string, string>)x.Cells[browserNameColumnIndex].Tag)["browser"] == eachBrowserName); foreach (var rowsWithCookiesOfCurrentProfileToDelete in rowsWithCookiesOfCurrentBrowserToDelete.GroupBy(x => ((Dictionary <string, string>)x.Cells[browserNameColumnIndex].Tag)["profile"])) { this.DeleteRowsWithCookiesOfSpecificBrowser(eachBrowserName, rowsWithCookiesOfCurrentProfileToDelete.Key, dgv, rowsWithCookiesOfCurrentProfileToDelete); } } } } else { this.DeleteRowsWithCookiesOfSpecificBrowser(browserName, profileName, dgv, dgvsrc.Cast <DataGridViewRow>()); } } }