Esempio n. 1
0
        // -------------------------------------------------------------------------------------
        /// <summary>
        /// Details DataGrid
        /// </summary>
        // -------------------------------------------------------------------------------------
        private void FillDetailsGrid(DBString DetailID)
        {
            try
              {
            string sortColumn = "PageIndex";
            int selectedRow = -1;

            // storing the previous sort order
            if (dtgDetails.DataSource != null)
            {
              sortColumn = ((DataTable) dtgDetails.DataSource).DefaultView.Sort;
            }

            // retrieving data
            DataTable dt = m_Template.Details.AllAsDatatable;
            dt.DefaultView.Sort = sortColumn;
            dtgDetails.DataSource = dt;

            // locates the row specified by ID param
            if (DetailID.Length > 0)
            {
              BindingManagerBase bm = dtgDetails.BindingContext[dtgDetails.DataSource, dtgDetails.DataMember];
              DataRow dr;
              for (int i = 0; i < bm.Count; i++)
              {
            dr = ((DataRowView) bm.Current).Row;
            if (DetailID.Equals(dr["ID"]))
            {
              selectedRow = i;
              break;
            }
            bm.Position += 1;
              }
            }

            // makes the row selected
            if (selectedRow <= ((DataTable) dtgDetails.DataSource).DefaultView.Count && selectedRow > -1)
            {
              dtgDetails.Select(selectedRow);
              dtgDetails.CurrentRowIndex = selectedRow;
            }
            else if (((DataTable) dtgDetails.DataSource).DefaultView.Count != 0)
            {
              dtgDetails.Select(0);
            }

            btnModifyDetail.Enabled = (((DataTable) dtgDetails.DataSource).DefaultView.Count != 0);
            btnPreview.Enabled = (((DataTable) dtgDetails.DataSource).DefaultView.Count != 0);
              }
              catch (Exception ex)
              {
            //	---	Log exception
            ExceptionManager.Publish(ex);
            //	---	Display Exception
            ErrorHandler.DisplayError("Hiba az adatok lekérdezése során", ex);
              }
        }