Beispiel #1
0
        private void LoadDgvCrashes()
        {
            int currentCellRow = 0;
            int currentCellCol = 0;

            if (dgvCrashes.CurrentCell != null)
            {
                currentCellRow = dgvCrashes.CurrentCell.RowIndex;
                currentCellCol = dgvCrashes.CurrentCell.ColumnIndex;
            }

            DataTable dataTable     = ApplicationError.GetAll();
            var       dataTableEnum = dataTable.AsEnumerable();

            dataTableEnum      = dataTableEnum.Where(x => x.Field <int>("StateCode") == 0);
            txtCrashCount.Text = dataTableEnum.Count().ToString();

            if (cboCrashesViews.SelectedIndex == 1)
            {
                dataTableEnum = dataTable.AsEnumerable();
                dataTableEnum = dataTableEnum.Where(x => x.Field <int>("StateCode") == 1);
            }

            if (dataTableEnum.Any())
            {
                dataTable = dataTableEnum.CopyToDataTable();
            }
            else
            {
                dataTable.Rows.Clear();
            }

            dgvCrashes.DataSource = dataTable;

            // Display/order the columns.
            dgvCrashes.Columns["CreatedBy"].Visible          = false;
            dgvCrashes.Columns["ModifiedBy"].Visible         = false;
            dgvCrashes.Columns["ModifiedOn"].Visible         = false;
            dgvCrashes.Columns["StateCode"].Visible          = false;
            dgvCrashes.Columns["Data"].Visible               = false;
            dgvCrashes.Columns["StackTrace"].Visible         = false;
            dgvCrashes.Columns["TimeStamp"].Visible          = false;
            dgvCrashes.Columns["ApplicationErrorId"].Visible = false;

            dataTable.Columns.Add("State");
            int i = 0;

            foreach (DataRow dr in dataTable.Rows)
            {
                if (dr["StateCode"].ToString().Equals("0"))
                {
                    dr["State"] = "Unresolved";
                }
                else
                {
                    dr["State"] = "Resolved";
                }
            }

            dgvCrashes.Columns["Message"].DisplayIndex   = 0;
            dgvCrashes.Columns["Source"].DisplayIndex    = 1;
            dgvCrashes.Columns["CreatedOn"].DisplayIndex = 2;
            dgvCrashes.Columns["State"].DisplayIndex     = 3;

            if (dgvCrashes.RowCount > 0 && dgvCrashes.ColumnCount > 0)
            {
                DataGridViewCell selectedCell = dgvCrashes.Rows[currentCellRow].Cells[currentCellCol];
                if (selectedCell != null && selectedCell.Visible)
                {
                    dgvCrashes.CurrentCell = selectedCell;
                }
                else
                {
                    dgvCrashes.CurrentCell = dgvCrashes.FirstDisplayedCell;
                }
            }
        }