private void ReverseMenuItem_Click(object sender, System.EventArgs e) { ListViewItem tempItem; try { //Exit if the list view is not in multi-select mode. if (!MyExtListView.MultiSelect) { return; } if (MyParentForm != null) { MyParentForm.Cursor = Cursors.WaitCursor; } MyExtListView.BeginUpdate(); for (int i = 0; i < MyExtListView.Items.Count; i++) { tempItem = MyExtListView.Items[i]; tempItem.Selected = !tempItem.Selected; } MyExtListView.EndUpdate(); if (MyParentForm != null) { MyParentForm.Cursor = Cursors.Default; } } catch (Exception ex) { MessageManager.ShowError(ex, "Unable to reverse selection.", MyParentForm); } }
public void ShowMatrix(string[,] matrix) { ColumnHeader[] colHeaderObjects; ListViewItem tempRow; int rowLimit, colLimit; rowLimit = Convert.ToInt32(Configuration.GetFromFile("ListRowLimit")); colLimit = Convert.ToInt32(Configuration.GetFromFile("ListColumnLimit")); if (matrix.GetLength(0) > rowLimit) { throw new Exception("Cannot show list. The number of rows exceeds the maximum limit " + rowLimit.ToString() + "."); } else if (matrix.GetLength(1) > colLimit) { throw new Exception("Cannot show list. The number of columns exceeds the maximum limit " + colLimit.ToString() + "."); } if (MyParentForm != null) { MyParentForm.Cursor = Cursors.WaitCursor; } MyExtListView.BeginUpdate(); colHeaderObjects = new ColumnHeader[matrix.GetLength(1)]; for (int i = 0; i < colHeaderObjects.GetLength(0); i++) { colHeaderObjects[i] = new ColumnHeader(); colHeaderObjects[i].Text = matrix[0, i]; } MyExtListView.Columns.AddRange(colHeaderObjects); for (int j = 1; j < matrix.GetLength(0); j++) { tempRow = new ListViewItem(matrix[j, 0]); for (int i = 1; i < matrix.GetLength(1); i++) { tempRow.SubItems.Add(matrix[j, i]); } MyExtListView.Items.Add(tempRow); } //Now after we have added values, it's time to set the column header width //to that of the widest text in the column. for (int i = 0; i < MyExtListView.Columns.Count; i++) { MyExtListView.Columns[i].Width = -2; } MyExtListView.EndUpdate(); RefreshCounterText(); if (MyParentForm != null) { MyParentForm.Cursor = Cursors.Default; } }
public void ShowFormattedTable(DataTable dTable, string sortExpression) { ListViewItem tempListViewItem; string columnFormatCode, columnDisplayName; int columnNameLength, colLimit; long rowLimit, rowCounter; System.Globalization.NumberFormatInfo numFrmter; IComparer tempComparer; rowLimit = long.MaxValue; //rowLimit = Convert.ToInt32(Configuration.GetFromFile("ListRowLimit")); colLimit = Convert.ToInt32(Configuration.GetFromFile("ListColumnLimit")); if (dTable.Rows.Count > rowLimit) { throw new Exception("Cannot show list. The number of rows exceeds the maximum limit " + rowLimit.ToString() + "."); } else if (dTable.Columns.Count > colLimit) { throw new Exception("Cannot show list. The number of columns exceeds the maximum limit " + colLimit.ToString() + "."); } MyDataTable = dTable; numFrmter = new System.Globalization.NumberFormatInfo(); numFrmter.PercentDecimalDigits = 2; numFrmter.PercentDecimalSeparator = "."; numFrmter.NumberDecimalDigits = 2; numFrmter.NumberDecimalSeparator = "."; if (MyParentForm != null) { MyParentForm.Cursor = Cursors.WaitCursor; } //Clear the list view. MyExtListView.Items.Clear(); MyExtListView.Columns.Clear(); MyExtListView.BeginUpdate(); //Turn off sorting before adding new rows, //but remember the previous sorter. tempComparer = MyExtListView.ListViewItemSorter; MyExtListView.ListViewItemSorter = null; //Add the column names, all except for the ID column. for (int i = 1; i < dTable.Columns.Count; i++) { columnNameLength = dTable.Columns[i].Caption.Length; //The column format code is stored in the extended properties. if (dTable.Columns[i].ExtendedProperties.ContainsKey("FormatCode")) { columnFormatCode = (string)dTable.Columns[i].ExtendedProperties["FormatCode"]; } else { columnFormatCode = ""; } columnDisplayName = dTable.Columns[i].ColumnName; if (columnFormatCode.StartsWith("I") || columnFormatCode.StartsWith("R") || columnFormatCode.StartsWith("P")) { MyExtListView.Columns.Add(columnDisplayName, 100, HorizontalAlignment.Right); } else { MyExtListView.Columns.Add(columnDisplayName, 100, HorizontalAlignment.Left); } } //Add the rows. rowCounter = 0; foreach (DataRow tempRow in dTable.Select(null, sortExpression)) { tempListViewItem = MyExtListView.Items.Add(tempRow[1].ToString()); tempListViewItem.Tag = tempRow[0].ToString(); tempListViewItem.UseItemStyleForSubItems = false; for (int i = 2; i < dTable.Columns.Count; i++) { if (dTable.Columns[i].ExtendedProperties.ContainsKey("FormatCode")) { columnFormatCode = (string)dTable.Columns[i].ExtendedProperties["FormatCode"]; } else { columnFormatCode = ""; } if (tempRow.IsNull(i)) { tempListViewItem.SubItems.Add(tempRow[i].ToString()); } else { switch (columnFormatCode) { case "IN": tempListViewItem.SubItems.Add(new AdvancedListView2.IntListViewSubItem(tempListViewItem, Convert.ToInt32(tempRow[i]))); break; case "RN": tempListViewItem.SubItems.Add(new AdvancedListView2.DoubleListViewSubItem(tempListViewItem, Convert.ToDouble(tempRow[i]), "N", numFrmter)); break; case "PN": tempListViewItem.SubItems.Add(new AdvancedListView2.DoubleListViewSubItem(tempListViewItem, Convert.ToDouble(tempRow[i]), "P", numFrmter)); break; case "IF": tempListViewItem.SubItems.Add(new AdvancedListView2.IntFailureListViewSubItem(tempListViewItem, Convert.ToInt32(tempRow[i]))); break; case "RF": tempListViewItem.SubItems.Add(new AdvancedListView2.DoubleFailureListViewSubItem(tempListViewItem, Convert.ToDouble(tempRow[i]), "N", numFrmter)); break; case "PF": tempListViewItem.SubItems.Add(new AdvancedListView2.DoubleFailureListViewSubItem(tempListViewItem, Convert.ToDouble(tempRow[i]), "P", numFrmter)); break; case "CF": tempListViewItem.SubItems.Add(new FailureListViewSubItem(tempListViewItem, tempRow[i].ToString())); break; default: tempListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(tempListViewItem, tempRow[i].ToString())); break; } } } rowCounter++; if (rowCounter >= rowLimit) { break; } } //Now after we have added values, it's time to set the column header width //to that of the widest text in the column. for (int i = 0; i < MyExtListView.Columns.Count; i++) { MyExtListView.Columns[i].Width = -2; } //Turn on sorting again (if the sorting is not performed by the sortExpression). MyExtListView.ListViewItemSorter = (sortExpression != null ? null : tempComparer); MyExtListView.EndUpdate(); //Select the first item if (MyExtListView.Items.Count > 0) { MyExtListView.Items[0].Selected = true; } RefreshCounterText(); if (MyParentForm != null) { MyParentForm.Cursor = Cursors.Default; } }