/// <summary> Constructor for a new instance of the Ad_Hoc_Report_Display_Form form </summary>
        /// <param name="Display_Set">Set of titles/items to display within this form</param>
        public Ad_Hoc_Report_Display_Form( DataSet Display_Set )
        {
            InitializeComponent();
            BackColor = Color.FromArgb(240, 240, 240);

            displaySet = Display_Set;

            // Check for values at each hierarchical level and author and publisher
            bool hasLevel1Data = false;
            bool hasLevel2Data = false;
            bool hasLevel3Data = false;
            bool hasAuthorData = false;
            bool hasPublisherData = false;
            bool hasDateData = false;

            // Move the date column to the right spot
            Display_Set.Tables[0].Columns["PubDate"].SetOrdinal(8);

            // Get the columns
            DataColumn level1Column = displaySet.Tables[0].Columns["Level1_Text"];
            DataColumn level2Column = displaySet.Tables[0].Columns["Level2_Text"];
            DataColumn level3Column = displaySet.Tables[0].Columns["Level3_Text"];
            DataColumn publisherColumn = displaySet.Tables[0].Columns["Publisher"];
            DataColumn authorColumn = displaySet.Tables[0].Columns["Author"];
            DataColumn dateColumn = displaySet.Tables[0].Columns["PubDate"];

            // Step through each row and check for data existence
            foreach (DataRow thisRow in Display_Set.Tables[0].Rows )
            {
                if ((hasLevel1Data) && (hasLevel2Data) && (hasLevel3Data) && (hasPublisherData) && (hasAuthorData) && ( hasDateData ))
                    break;
                if ((!hasLevel1Data) && (thisRow[level1Column].ToString().Length > 0))
                    hasLevel1Data = true;
                if ((!hasLevel2Data) && (thisRow[level2Column].ToString().Length > 0))
                    hasLevel2Data = true;
                if ((!hasLevel3Data) && (thisRow[level3Column].ToString().Length > 0))
                    hasLevel3Data = true;
                if ((!hasPublisherData) && (thisRow[publisherColumn].ToString().Length > 0))
                    hasPublisherData = true;
                if ((!hasAuthorData) && (thisRow[authorColumn].ToString().Length > 0))
                    hasAuthorData = true;
                if ((!hasDateData) && (thisRow[dateColumn].ToString().Length > 0))
                    hasDateData = true;
            }

            // Create the custom grid
            gridPanel = new CustomGrid_Panel
                            {Size = new Size(panel1.Width - 2, panel1.Height - 2), Location = new Point(0, 0)};

            // Configure some table level style settings
            gridPanel.Style.Default_Column_Width = 80;
            gridPanel.Style.Default_Column_Color = Color.LightBlue;
            gridPanel.Style.Header_Back_Color = Color.DarkBlue;
            gridPanel.Style.Header_Fore_Color = Color.White;

            // Set the background and border style
            gridPanel.BackColor = Color.WhiteSmoke;
            gridPanel.BorderStyle = BorderStyle.FixedSingle;
            gridPanel.Anchor = (((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
            panel1.Controls.Add(gridPanel);

            gridPanel.DataTable = displaySet.Tables[0];

            gridPanel.Current_Sort_String = "BibID ASC, VID ASC";

            // Configure for this table
            gridPanel.Style.Column_Styles[1].Width = 50;
            gridPanel.Style.Column_Styles[2].Visible = false;
            gridPanel.Style.Column_Styles[3].Visible = false;
            gridPanel.Style.Column_Styles[4].Visible = false;
            gridPanel.Style.Column_Styles[5].Width = SMaRT_UserSettings.Ad_Hoc_Report_Form_Title_Width;
            gridPanel.Style.Column_Styles[5].BackColor = Color.White;
            gridPanel.Style.Column_Styles[6].BackColor = Color.White;

            if (!hasAuthorData)
                gridPanel.Style.Column_Styles[6].Width = SMaRT_UserSettings.Ad_Hoc_Report_Form_Author_Width;
            else
                gridPanel.Style.Column_Styles[6].Visible = false;

            gridPanel.Style.Column_Styles[7].BackColor = Color.White;
            if (hasPublisherData)
                gridPanel.Style.Column_Styles[7].Width = SMaRT_UserSettings.Ad_Hoc_Report_Form_Publisher_Width;
            else
                gridPanel.Style.Column_Styles[7].Visible = false;

            gridPanel.Style.Column_Styles[8].BackColor = Color.White;
            if (hasDateData)
                gridPanel.Style.Column_Styles[8].Width = SMaRT_UserSettings.Ad_Hoc_Report_Form_Date_Width;
            else
                gridPanel.Style.Column_Styles[8].Visible = false;

            if (hasLevel1Data)
                gridPanel.Style.Column_Styles[9].Width =  SMaRT_UserSettings.Ad_Hoc_Report_Form_Level1_Width;
            else
                gridPanel.Style.Column_Styles[9].Visible = false;

            gridPanel.Style.Column_Styles[9].Text_Alignment = HorizontalAlignment.Left;
            gridPanel.Style.Column_Styles[10].Visible = false;
            if (hasLevel2Data)
                gridPanel.Style.Column_Styles[11].Width = SMaRT_UserSettings.Ad_Hoc_Report_Form_Level2_Width;
            else
                gridPanel.Style.Column_Styles[11].Visible = false;
            gridPanel.Style.Column_Styles[11].Text_Alignment = HorizontalAlignment.Left;
            gridPanel.Style.Column_Styles[12].Visible = false;
            if (hasLevel3Data)
                gridPanel.Style.Column_Styles[13].Width = SMaRT_UserSettings.Ad_Hoc_Report_Form_Level3_Width;
            else
                gridPanel.Style.Column_Styles[13].Visible = false;
            gridPanel.Style.Column_Styles[13].Text_Alignment = HorizontalAlignment.Left;
            gridPanel.Style.Column_Styles[14].Visible = false;
            gridPanel.Style.Column_Styles[15].Visible = false;
            gridPanel.Style.Column_Styles[16].Visible = false;
            gridPanel.Style.Column_Styles[17].Visible = false;
            gridPanel.Style.Column_Styles[18].Visible = false;

            gridPanel.Style.Column_Styles[20].Visible = false;
            gridPanel.Style.Column_Styles[21].Header_Text = "Comments";
            gridPanel.Style.Column_Styles[24].Header_Text = "Digitized";
            gridPanel.Style.Column_Styles[24].Short_Date_Format = true;
            gridPanel.Style.Column_Styles[25].Header_Text = "Processed";
            gridPanel.Style.Column_Styles[25].Short_Date_Format = true;
            gridPanel.Style.Column_Styles[26].Header_Text = "QC'd";
            gridPanel.Style.Column_Styles[26].Short_Date_Format = true;
            gridPanel.Style.Column_Styles[27].Header_Text = "Online";
            gridPanel.Style.Column_Styles[27].Short_Date_Format = true;
            gridPanel.Style.Column_Styles[38].Visible = false;

            // Set some sort values
            gridPanel.Style.Column_Styles[9].Ascending_Sort = "Level1_Index ASC, Level2_Index ASC, Level3_Index ASC";
            gridPanel.Style.Column_Styles[9].Descending_Sort = "Level1_Index DESC, Level2_Index DESC, Level3_Index DESC";
            gridPanel.Style.Column_Styles[11].Ascending_Sort = "Level2_Index ASC, Level3_Index ASC";
            gridPanel.Style.Column_Styles[11].Descending_Sort = "Level2_Index DESC, Level3_Index DESC";
            gridPanel.Style.Column_Styles[5].Ascending_Sort = "SortTitle ASC, Level1_Index ASC, Level2_Index ASC, Level3_Index ASC";
            gridPanel.Style.Column_Styles[5].Descending_Sort = "SortTitle DESC, Level1_Index DESC, Level2_Index DESC, Level3_Index DESC";
            gridPanel.Style.Column_Styles[8].Ascending_Sort = "SortDate ASC, SortTitle ASC, Level1_Index ASC, Level2_Index ASC, Level3_Index ASC";
            gridPanel.Style.Column_Styles[8].Descending_Sort = "SortDate DESC, SortTitle DESC, Level1_Index DESC, Level2_Index DESC, Level3_Index DESC";

            gridPanel.Double_Clicked += gridPanel_Double_Clicked;
            gridPanel.Clipboard_Copy_Requested += new CustomGrid_Panel_Delegate_Multiple(gridPanel_Clipboard_Copy_Requested);

            // Add the context menu
            gridPanel.Set_Context_Menus(null, contextMenu1);

            // Add the object to print
            gridPrinter = new CustomGrid_Printer(gridPanel, printDocument1);

            // Set the hits value
            hitCountLabel.Text = "Your search resulted in " + number_to_string(displaySet.Tables[0].Rows.Count) + " items in " + number_to_string(displaySet.Tables[1].Rows.Count) + " titles";

            // Set the size correctly
            Size = SMaRT_UserSettings.Ad_Hoc_Report_Form_Size;
            int screen_width = Screen.PrimaryScreen.WorkingArea.Width;
            int screen_height = Screen.PrimaryScreen.WorkingArea.Height;
            if ((Width > screen_width) || (Height > screen_height) || (SMaRT_UserSettings.Ad_Hoc_Report_Form_Maximized))
                WindowState = FormWindowState.Maximized;

            // GEt the username
            username = Environment.UserName;

            // Set the action on click
            if (SMaRT_UserSettings.Ad_Hoc_Form_Action_On_Click == View_Items_Form_Action_On_Click_Enum.Open_On_Web)
            {
                openItemFromWebMenuItem.Checked = true;
                viewItemFormMenuItem.Checked = false;
            }
            else
            {
                openItemFromWebMenuItem.Checked = false;
                viewItemFormMenuItem.Checked = true;
            }
        }
        /// <summary> Constructor for a new instance of this class </summary>
        /// <param name="resultSet"> Results set to display </param>
        //public Results_Form(DataTable resultSet, ArrayList resultList, SobekCM_Item bibPackage)
        public Results_Form(DataTable resultSet, Importer_Type_Enum importerType, bool preview_mode )
        {
            // Initialize this form
            InitializeComponent();

            // Perform some additional work if this was not XP theme
            if (!Windows_Appearance_Checker.is_XP_Theme)
            {
                saveButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                closeButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            }

            // Save these values
                this.resultTable = resultSet;

            // Show the result set
            customGrid_Panel1.DataTable = resultSet;

            // Set some overall styles
            customGrid_Panel1.Style.Default_Column_Color = System.Drawing.Color.LightBlue;
            customGrid_Panel1.Style.Header_Back_Color = Color.DarkBlue;
            customGrid_Panel1.Style.Header_Fore_Color = Color.White;
            customGrid_Panel1.Style.Default_Column_Color = System.Drawing.Color.LightBlue;

            // assign the context menu to the custom grid
            this.customGrid_Panel1.Double_Clicked += new CustomGrid_Panel_Delegate_Single(this.customGrid_Panel1_Double_Clicked);
            this.customGrid_Panel1.ContextMenu = this.contextMenu1;

            // determine what should be displayed on the results form
            switch (importerType)
            {
                case Importer_Type_Enum.MARC:
                    // set column styles for displaying the results table
                    customGrid_Panel1.Style.Column_Styles[0].Visible = false;
                    customGrid_Panel1.Style.Column_Styles[1].Header_Text = "Bib ID";
                    customGrid_Panel1.Style.Column_Styles[1].Fixed_Print_Width = 100;
                    customGrid_Panel1.Style.Column_Styles[1].Width = 100;
                    customGrid_Panel1.Style.Column_Styles[2].Header_Text = "VID";
                    customGrid_Panel1.Style.Column_Styles[2].Width = 70;
                    customGrid_Panel1.Style.Column_Styles[2].Fixed_Print_Width = 65;
                    customGrid_Panel1.Style.Column_Styles[3].Header_Text = "Comment";
                    customGrid_Panel1.Style.Column_Styles[3].Width = 200;
                    customGrid_Panel1.Style.Column_Styles[4].Visible = false;
                    customGrid_Panel1.Style.Column_Styles[5].Header_Text = "Aleph";
                    customGrid_Panel1.Style.Column_Styles[5].Width = 70;
                    customGrid_Panel1.Style.Column_Styles[6].Header_Text = "OCLC";
                    customGrid_Panel1.Style.Column_Styles[6].Width = 70;
                    customGrid_Panel1.Style.Column_Styles[7].Header_Text = "Bib Title";
                    customGrid_Panel1.Style.Column_Styles[7].Width = 300;
                    customGrid_Panel1.Style.Column_Styles[7].BackColor = Color.White;
                    customGrid_Panel1.Style.Column_Styles[8].Header_Text = "Volume Title";
                    customGrid_Panel1.Style.Column_Styles[8].Width = 300;
                    customGrid_Panel1.Style.Column_Styles[8].BackColor = Color.White;
                    customGrid_Panel1.Style.Column_Styles[9].Header_Text = "Author";
                    customGrid_Panel1.Style.Column_Styles[9].Width = 150;
                    customGrid_Panel1.Style.Column_Styles[9].BackColor = Color.White;
                    customGrid_Panel1.Style.Column_Styles[10].Header_Text = "Type";
                    customGrid_Panel1.Style.Column_Styles[10].Width = 70;
                    customGrid_Panel1.Style.Column_Styles[11].Header_Text = "Project";
                    customGrid_Panel1.Style.Column_Styles[11].Width = 70;

                    // set text on menu item
                    this.detailsMenuItem.Text = "Show MARC XML";
                    this.detailsMenuItem_ContextMenuItem.Text = "Show MARC XML";
                    this.Text = "MARC Importer - Results Form";
                    break;

                case Importer_Type_Enum.METS:
                case Importer_Type_Enum.Spreadsheet:
                    // set column styles for displaying the results table
                    customGrid_Panel1.Style.Column_Styles[0].Visible = false;
                    customGrid_Panel1.Style.Column_Styles[1].Header_Text = "Bib ID";
                    customGrid_Panel1.Style.Column_Styles[1].Width = 100;
                    customGrid_Panel1.Style.Column_Styles[1].Fixed_Print_Width = 100;
                    customGrid_Panel1.Style.Column_Styles[2].Header_Text = "VID";
                    customGrid_Panel1.Style.Column_Styles[2].Width = 70;
                    customGrid_Panel1.Style.Column_Styles[2].Fixed_Print_Width = 65;
                    customGrid_Panel1.Style.Column_Styles[3].Header_Text = "Comment";
                    customGrid_Panel1.Style.Column_Styles[3].Width = 200;
                    customGrid_Panel1.Style.Column_Styles[4].Visible = false;
                    customGrid_Panel1.Style.Column_Styles[5].Header_Text = "Aleph";
                    customGrid_Panel1.Style.Column_Styles[5].Width = 70;
                    customGrid_Panel1.Style.Column_Styles[6].Header_Text = "OCLC";
                    customGrid_Panel1.Style.Column_Styles[6].Width = 70;
                    customGrid_Panel1.Style.Column_Styles[7].Header_Text = "Bib Title";
                    customGrid_Panel1.Style.Column_Styles[7].Width = 300;
                    customGrid_Panel1.Style.Column_Styles[7].BackColor = Color.White;
                    customGrid_Panel1.Style.Column_Styles[8].Header_Text = "Volume Title";
                    customGrid_Panel1.Style.Column_Styles[8].Width = 300;
                    customGrid_Panel1.Style.Column_Styles[8].BackColor = Color.White;
                    customGrid_Panel1.Style.Column_Styles[9].Header_Text = "Author";
                    customGrid_Panel1.Style.Column_Styles[9].Width = 150;
                    customGrid_Panel1.Style.Column_Styles[9].BackColor = Color.White;
                    customGrid_Panel1.Style.Column_Styles[10].Header_Text = "Type";
                    customGrid_Panel1.Style.Column_Styles[10].Width = 70;
                    customGrid_Panel1.Style.Column_Styles[11].Header_Text = "Project";
                    customGrid_Panel1.Style.Column_Styles[11].Width = 70;

                    // set text on menu item
                    this.detailsMenuItem.Text = "Show METS";
                    this.detailsMenuItem_ContextMenuItem.Text = "Show METS";
                    if ( importerType == Importer_Type_Enum.METS )
                        this.Text = "METS Importer - Results Form";
                    else
                        this.Text = "SpreadSheet Importer - Results Form";
                    break;
            }

            if (preview_mode)
            {
                this.Text = this.Text + " (PREVIEW ONLY!)";
            }

            // Set the default print as landscape
            printDocument1.DefaultPageSettings.Landscape = true;

            // Create the object to print the grid
            gridPrinter = new CustomGrid_Printer( customGrid_Panel1, printDocument1 );
        }
        private void Show_Items(DataSet dataSet, string Code_for_browse)
        {
            database_dataset_to_tracking_bib_table(dataSet);

            if ((displayTable == null) || (displayTable.Rows.Count == 0))
            {
                if (gridPanel != null)
                {
                    mainPanel.Controls.Remove(gridPanel);
                    gridPanel = null;
                }
                Clear_Items(false);
                hitCountLabel.Text = "No Matches Found";
            }
            else
            {
                instructionLabel.Hide();
                if (gridPanel == null)
                {
                    gridPanel = new CustomGrid_Panel
                                    {
                                        Size = new Size(mainPanel.Width - 2, mainPanel.Height - 2),
                                        Location = new Point(0, 0)
                                    };

                    // Configure some table level style settings
                    gridPanel.Style.Default_Column_Width = 80;
                    gridPanel.Style.Default_Column_Color = Color.LightBlue;
                    gridPanel.Style.Header_Back_Color = Color.DarkBlue;
                    gridPanel.Style.Header_Fore_Color = Color.White;

                    //// initial the sort option
                    //if (this.Current_Sort_String.Length == 0)
                    //    this.Current_Sort_String = "BibID ASC";// Use the table from the database as the data source
                    //this.DataTable = sourceTable;

                    // Set the background and border style
                    gridPanel.BackColor = Color.WhiteSmoke;
                    gridPanel.BorderStyle = BorderStyle.FixedSingle;
                    gridPanel.Anchor = (((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
                    mainPanel.Controls.Add(gridPanel);

                    // Add the event to the grid panel
                    gridPanel.Double_Clicked += gridPanel_Double_Clicked;
                    gridPanel.Clipboard_Copy_Requested +=new CustomGrid_Panel_Delegate_Multiple(gridPanel_Clipboard_Copy_Requested);

                    // Add the context menu
                    gridPanel.Set_Context_Menus(null, contextMenu1);

                    // Add the object to print
                    gridPrinter = new CustomGrid_Printer(gridPanel, printDocument1);
                }
                else
                {
                    // Save the column sizes
                    SMaRT_UserSettings.Discovery_Form_Title_Width = gridPanel.Style.Column_Styles[5].Width;
                    SMaRT_UserSettings.Discovery_Form_Author_Width = gridPanel.Style.Column_Styles[6].Width;
                    SMaRT_UserSettings.Discovery_Form_Publisher_Width = gridPanel.Style.Column_Styles[7].Width;
                }

                gridPanel.DataTable = displayTable;

                gridPanel.Current_Sort_String = "BibID ASC";

                // Configure for this table
                gridPanel.Style.Primary_Key_Column = 0;
                gridPanel.Style.Column_Styles[0].Visible = false;
                gridPanel.Style.Column_Styles[1].Fixed_Print_Width = 100;
                gridPanel.Style.Column_Styles[2].Width = 85;
                gridPanel.Style.Column_Styles[2].Fixed_Print_Width = 65;
                gridPanel.Style.Column_Styles[3].Fixed_Print_Width = 100;
                gridPanel.Style.Column_Styles[4].Fixed_Print_Width = 100;
                gridPanel.Style.Column_Styles[5].Width = SMaRT_UserSettings.Discovery_Form_Title_Width;
                gridPanel.Style.Column_Styles[5].Text_Alignment = HorizontalAlignment.Left;
                gridPanel.Style.Column_Styles[5].BackColor = Color.White;
                gridPanel.Style.Column_Styles[6].Width = SMaRT_UserSettings.Discovery_Form_Author_Width;
                gridPanel.Style.Column_Styles[6].Text_Alignment = HorizontalAlignment.Left;
                gridPanel.Style.Column_Styles[6].BackColor = Color.White;
                gridPanel.Style.Column_Styles[7].Width = SMaRT_UserSettings.Discovery_Form_Publisher_Width;
                gridPanel.Style.Column_Styles[7].Text_Alignment = HorizontalAlignment.Left;
                gridPanel.Style.Column_Styles[7].BackColor = Color.White;
                gridPanel.Style.Column_Styles[8].Width = 100;
                gridPanel.Style.Column_Styles[9].Width = 120;
                gridPanel.Style.Column_Styles[10].Visible = false;
                gridPanel.Style.Column_Styles[11].Visible = false;

                gridPanel.Style.Column_Styles[3].Ascending_Sort = "ALEPH ASC, BibID ASC";
                gridPanel.Style.Column_Styles[3].Descending_Sort = "ALEPH DESC, BibID DESC";

                gridPanel.Style.Column_Styles[4].Ascending_Sort = "OCLC ASC, BibID ASC";
                gridPanel.Style.Column_Styles[4].Descending_Sort = "OCLC DESC, BibID DESC";

                gridPanel.Style.Column_Styles[5].Ascending_Sort = "SortTitle ASC, BibID ASC";
                gridPanel.Style.Column_Styles[5].Descending_Sort = "SortTitle DESC, BibID DESC";

                gridPanel.Style.Column_Styles[8].Ascending_Sort = "Material_Type ASC, BibID ASC";
                gridPanel.Style.Column_Styles[8].Descending_Sort = "Material_Type DESC, BibID DESC";

                gridPanel.Style.Column_Styles[9].Ascending_Sort = "Aggregations ASC, BibID ASC";
                gridPanel.Style.Column_Styles[9].Descending_Sort = "Aggregations DESC, BibID DESC";

                if (Code_for_browse.Length > 0)
                {
                    switch (displayTable.Rows.Count)
                    {
                        case 1: hitCountLabel.Text = "Your browse resulted in one matching title"; break;
                        default: hitCountLabel.Text = "Your browse resulted in " + number_to_string(displayTable.Rows.Count) + " matching titles"; break;
                    }
                }
                else
                {
                    hitCountLabel.Text = "Your search resulted in " + number_to_string(itemCount) + " items in " + number_to_string(titleCount) + " titles";
                }

                // Determine if any ALEPH, OCLC, AUTHOR, or PUBLISHER data is present
                bool checkingAleph = true;
                bool checkingOclc = true;
                bool checkingAuthor = true;
                bool checkingPublisher = true;
                DataColumn alephColumn = displayTable.Columns["Aleph"];
                DataColumn oclcColumn = displayTable.Columns["OCLC"];
                DataColumn authorColumn = displayTable.Columns["Author"];
                DataColumn publisherColumn = displayTable.Columns["Publisher"];
                foreach (DataRow thisRow in displayTable.Rows)
                {
                    if (checkingAleph)
                    {
                        if (thisRow[alephColumn].ToString().Trim().Length > 0)
                        {
                            checkingAleph = false;
                        }
                    }

                    if (checkingOclc)
                    {
                        if (thisRow[oclcColumn].ToString().Trim().Length > 0)
                        {
                            checkingOclc = false;
                        }
                    }

                    if (checkingAuthor)
                    {
                        if (thisRow[authorColumn].ToString().Trim().Length > 0)
                        {
                            checkingAuthor = false;
                        }
                    }

                    if (checkingPublisher)
                    {
                        if (thisRow[publisherColumn].ToString().Trim().Length > 0)
                        {
                            checkingPublisher = false;
                        }
                    }

                    if ((!checkingAleph) && (!checkingAuthor) && (!checkingOclc) && (!checkingPublisher))
                        break;
                }

                // Set the visibility of the columns based on the data
                gridPanel.Style.Column_Styles[3].Visible = !checkingAleph;
                gridPanel.Style.Column_Styles[4].Visible = !checkingOclc;
                gridPanel.Style.Column_Styles[6].Visible = !checkingAuthor;
                gridPanel.Style.Column_Styles[7].Visible = !checkingPublisher;

                // Enable the menu items which are now applicable
                saveAsMenuItem.Enabled = true;
                printMenuItem.Enabled = true;
                printTrackingSheetsMenuItem.Enabled = true;
                editSerialHierarchyToolStripMenuItem.Enabled = true;
                viewAdHocReportMenuItem.Enabled = true;
                setTrackingBoxToolStripMenuItem.Enabled = true;
                editDispositionAdviceMenuItem.Enabled = true;
                updateItemDispositionMenuItem.Enabled = true;
                addWorklogHistoryEntryMenuItem.Enabled = true;
                updateBornDigitalFlagMenuItem.Enabled = true;
                updateMaterialReceivedDateMenuItem.Enabled = true;

                // Now, some final code if there was only one result
                if ((displayTable.Rows.Count == 1) && (SMaRT_UserSettings.Item_Discovery_Form_Single_Result_Action == Single_Result_Action_Enum.Show_Details_For_Single_Item))
                {
                    // What is the currently selected action?
                    if (openItemGroupOnWebMenuItem.Checked)
                    {
                        string bibid = displayTable.Rows[0]["BibID"].ToString();
                        string vid = displayTable.Rows[0]["VID"].ToString();
                        string url = SobekCM_Library_Settings.System_Base_URL+ bibid;
                        if (vid.IndexOf("(") < 0)
                        {
                            url = url + "/" + vid;
                        }

                        try
                        {
                            Process openOnWeb = new Process {StartInfo = {FileName = url}};
                            openOnWeb.Start();
                        }
                        catch
                        {
                            MessageBox.Show("Error opening item group from the web.     ", "Browser Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        // Save the current size
                        SMaRT_UserSettings.Item_Discovery_Form_Size = Size;
                        SMaRT_UserSettings.Save();

                        // Now, show the row
                        View_Item_Group_Form showForm = new View_Item_Group_Form(displayTable.Rows[0]);
                        Hide();
                        showForm.ShowDialog();
                        Show();
                    }
                }

                gridPanel.ReDraw();
                gridPanel.Focus();
            }
        }
        private void show_all_volumes()
        {
            SobekCM_Items_In_Title testSet1 = SobekCM_Database.Tracking_Multiple_Volumes(bibid, null);
            if (testSet1 == null) return;

            childTable = testSet1.Item_Table;

            // Create the table to display now
            displayTable = new DataTable("Items");
            DataColumn returnItemIdColumn = displayTable.Columns.Add("ItemID", Type.GetType("System.Int32"));
            DataColumn returnVidColumn = displayTable.Columns.Add("VID");
            DataColumn returnTitleColumn = displayTable.Columns.Add("Volume_Title");
            DataColumn returnAuthorColumn = displayTable.Columns.Add("Author");
            DataColumn returnPublisherColumn = displayTable.Columns.Add("Publisher");
            DataColumn returnDateColumn = displayTable.Columns.Add("PubDate");
            DataColumn returnLevel1TextColumn = displayTable.Columns.Add("Level1_Text");
            DataColumn returnLevel1IndexColumn = displayTable.Columns.Add("Level1_Index", Type.GetType("System.Int32"));
            DataColumn returnLevel2TextColumn = displayTable.Columns.Add("Level2_Text");
            DataColumn returnLevel2IndexColumn = displayTable.Columns.Add("Level2_Index", Type.GetType("System.Int32"));
            DataColumn returnLevel3TextColumn = displayTable.Columns.Add("Level3_Text");
            DataColumn returnLevel3IndexColumn = displayTable.Columns.Add("Level3_Index", Type.GetType("System.Int32"));
            DataColumn returnAggregationsColumn = displayTable.Columns.Add("Aggregations");
            DataColumn returnAccessColumn = displayTable.Columns.Add("Access");
            //   DataColumn returnInHandColumn = displayTable.Columns.Add("In_Hand", Type.GetType("System.Boolean"));
            DataColumn returnTrackingBoxColumn = displayTable.Columns.Add("Tracking_Box");
            DataColumn returnMilestoneBoxColumn = displayTable.Columns.Add("Last_Milestone");
            DataColumn returnArchivedColumn = displayTable.Columns.Add("Archived");
            //   DataColumn returnBornDigitalColumn = displayTable.Columns.Add("Born_Digital", Type.GetType("System.Boolean"));
            DataColumn returnDispositionColumn = displayTable.Columns.Add("Disposition_Date");
            DataColumn returnSortTitleColumn = displayTable.Columns.Add("SortTitle");
            DataColumn returnSortDateColumn = displayTable.Columns.Add("SortDate");

            // Add this to a set to facilitate saving to XML later
            DataSet displaySet = new DataSet("Items_In_Title");
            displaySet.Tables.Add(displayTable);

            // Get column references for the source table
            DataColumn itemIdColumn = childTable.Columns["ItemID"];
            DataColumn vidColumn = childTable.Columns["VID"];
            DataColumn titleColumn = childTable.Columns["Title"];
            DataColumn authorColumn = childTable.Columns["Author"];
            DataColumn publisherColumn = childTable.Columns["Publisher"];
            DataColumn level1TextColumn = childTable.Columns["Level1_Text"];
            DataColumn level1IndexColumn = childTable.Columns["Level1_Index"];
            DataColumn level2TextColumn = childTable.Columns["Level2_Text"];
            DataColumn level2IndexColumn = childTable.Columns["Level2_Index"];
            DataColumn level3TextColumn = childTable.Columns["Level3_Text"];
            DataColumn level3IndexColumn = childTable.Columns["Level3_Index"];
            DataColumn accessColumn = childTable.Columns["IP_Restriction_Mask"];
            DataColumn aggregationsColumn = childTable.Columns["AggregationCodes"];
            DataColumn trackingBoxColumn = childTable.Columns["Tracking_Box"];
            DataColumn dispositionColumn = childTable.Columns["Disposition_Date"];
            DataColumn dateColumn = childTable.Columns["PubDate"];
            DataColumn sortDateColumn = childTable.Columns["SortDate"];
            DataColumn sortTitleColumn = childTable.Columns["SortTitle"];
            DataColumn milestoneColumn = childTable.Columns["Last_Milestone"];
            DataColumn localArchiveColumn = childTable.Columns["Locally_Archived"];
            DataColumn remoteArchiveColumn = childTable.Columns["Remotely_Archived"];

            // Check for values at each hierarchical level
            bool hasLevel1Data = false;
            bool hasLevel2Data = false;
            bool hasLevel3Data = false;
            bool hasPublisherData = false;
            bool hasAuthorData = false;
            bool hasDateData = false;

            // Copy over the applicable rows
            foreach (DataRow thisRow in childTable.Rows)
            {
                DataRow newRow = displayTable.NewRow();
                newRow[returnItemIdColumn] = thisRow[itemIdColumn];
                newRow[returnVidColumn] = thisRow[vidColumn];
                newRow[returnTitleColumn] = thisRow[titleColumn];
                newRow[returnAuthorColumn] = thisRow[authorColumn];
                newRow[returnPublisherColumn] = thisRow[publisherColumn];
                newRow[returnDateColumn] = thisRow[dateColumn];
                newRow[returnLevel1TextColumn] = thisRow[level1TextColumn];
                newRow[returnLevel1IndexColumn] = thisRow[level1IndexColumn];
                newRow[returnLevel2TextColumn] = thisRow[level2TextColumn];
                newRow[returnLevel2IndexColumn] = thisRow[level2IndexColumn];
                newRow[returnLevel3TextColumn] = thisRow[level3TextColumn];
                newRow[returnLevel3IndexColumn] = thisRow[level3IndexColumn];
                newRow[returnAggregationsColumn] = thisRow[aggregationsColumn].ToString().Trim().Replace("  ", "").Replace(" ", ",");
                newRow[returnTrackingBoxColumn] = thisRow[trackingBoxColumn];
                newRow[returnDispositionColumn] = thisRow[dispositionColumn];
                newRow[returnSortDateColumn] = thisRow[sortDateColumn];
                newRow[returnSortTitleColumn] = thisRow[sortTitleColumn];

                int access = Convert.ToInt32(thisRow[accessColumn]);
                if (access < 0)
                    newRow[returnAccessColumn] = "private";
                if (access == 0)
                    newRow[returnAccessColumn] = "public";
                if (access > 0)
                    newRow[returnAccessColumn] = "restricted";
                displayTable.Rows.Add(newRow);

                // Compute the last milestone
                int last_milestone = Convert.ToInt32(thisRow[milestoneColumn]);
                switch( last_milestone )
                {
                    case 1:
                        newRow[returnMilestoneBoxColumn] = "Digital Acquisition";
                        break;

                    case 2:
                        newRow[returnMilestoneBoxColumn] = "Post-Acquisition Processing";
                        break;

                    case 3:
                        newRow[returnMilestoneBoxColumn] = "Quality Control";
                        break;

                    case 4:
                        newRow[returnMilestoneBoxColumn] = "Online Complete";
                        break;

                    default:
                        newRow[returnMilestoneBoxColumn] = String.Empty;
                        break;
                }

                // Determine the archiving
                bool locally_archived = false;
                bool remotely_archived = false;
                if (( thisRow[localArchiveColumn] != DBNull.Value ) && (  thisRow[localArchiveColumn] != null ))
                    locally_archived = true;
                if ((thisRow[remoteArchiveColumn] != DBNull.Value) && (thisRow[remoteArchiveColumn] != null))
                    remotely_archived = true;
                if (( !locally_archived ) && ( !remotely_archived ))
                    newRow[returnArchivedColumn] = String.Empty;
                if ((!locally_archived) && (remotely_archived))
                    newRow[returnArchivedColumn] = "Remote";
                if ((locally_archived) && (!remotely_archived))
                    newRow[returnArchivedColumn] = "Local";
                if ((locally_archived) && (remotely_archived))
                    newRow[returnArchivedColumn] = "Both";

                if (!hasAuthorData)
                {
                    if (newRow[returnAuthorColumn].ToString().Length > 0)
                        hasAuthorData = true;
                }
                if (!hasPublisherData)
                {
                    if (newRow[returnPublisherColumn].ToString().Length > 0)
                        hasPublisherData = true;
                }
                if (!hasLevel1Data)
                {
                    if (newRow[returnLevel1TextColumn].ToString().Length > 0)
                        hasLevel1Data = true;
                }
                if (!hasLevel2Data)
                {
                    if (newRow[returnLevel2TextColumn].ToString().Length > 0)
                        hasLevel2Data = true;
                }
                if (!hasLevel3Data)
                {
                    if (newRow[returnLevel3TextColumn].ToString().Length > 0)
                        hasLevel3Data = true;
                }
                if (!hasDateData)
                {
                    if (newRow[returnDateColumn].ToString().Length > 0)
                        hasDateData = true;
                }
            }

            if (gridPanel == null)
            {
                gridPanel = new CustomGrid_Panel
                                {
                                    Size = new Size(volumesPanel.Width - 2, volumesPanel.Height - 2),
                                    Location = new Point(0, 0)
                                };
                gridPanel.Clipboard_Copy_Requested += new CustomGrid_Panel_Delegate_Multiple(gridPanel_Clipboard_Copy_Requested);

            }
            else
            {
                SMaRT_UserSettings.View_Item_Group_Form_Title_Width = gridPanel.Style.Column_Styles[2].Width;
                if (gridPanel.Style.Column_Styles[3].Visible)
                    SMaRT_UserSettings.View_Item_Group_Form_Author_Width = gridPanel.Style.Column_Styles[3].Width;
                if (gridPanel.Style.Column_Styles[4].Visible)
                    SMaRT_UserSettings.View_Item_Group_Form_Publisher_Width = gridPanel.Style.Column_Styles[4].Width;
                if (gridPanel.Style.Column_Styles[5].Visible)
                    SMaRT_UserSettings.View_Item_Group_Form_Date_Width = gridPanel.Style.Column_Styles[5].Width;
                if (gridPanel.Style.Column_Styles[6].Visible)
                    SMaRT_UserSettings.View_Item_Group_Form_Level1_Width = gridPanel.Style.Column_Styles[6].Width;
                if (gridPanel.Style.Column_Styles[8].Visible)
                    SMaRT_UserSettings.View_Item_Group_Form_Level2_Width = gridPanel.Style.Column_Styles[8].Width;
                if (gridPanel.Style.Column_Styles[10].Visible)
                    SMaRT_UserSettings.View_Item_Group_Form_Level3_Width = gridPanel.Style.Column_Styles[10].Width;
            }

            // Configure some table level style settings
            gridPanel.Style.Default_Column_Width = 80;
            gridPanel.Style.Default_Column_Color = Color.LightBlue;
            gridPanel.Style.Header_Back_Color = Color.DarkBlue;
            gridPanel.Style.Header_Fore_Color = Color.White;

            //// initial the sort option
            //if (this.Current_Sort_String.Length == 0)
            //    this.Current_Sort_String = "BibID ASC";// Use the table from the database as the data source
            //this.DataTable = sourceTable;

            // Set the background and border style
            gridPanel.BackColor = Color.WhiteSmoke;
            gridPanel.BorderStyle = BorderStyle.FixedSingle;
            gridPanel.Anchor = (((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
            volumesPanel.Controls.Add(gridPanel);

            gridPanel.DataTable = displayTable;

            gridPanel.Current_Sort_String = "VID ASC";

            // Configure for this table
            gridPanel.Style.Column_Styles[0].Visible = false;
            gridPanel.Style.Column_Styles[1].Width = 50;
            gridPanel.Style.Column_Styles[1].Header_Text = "VID #";
            gridPanel.Style.Column_Styles[1].Fixed_Print_Width = 65;
            gridPanel.Style.Column_Styles[2].Width = SMaRT_UserSettings.View_Item_Group_Form_Title_Width;
            gridPanel.Style.Column_Styles[2].Text_Alignment = HorizontalAlignment.Left;
            gridPanel.Style.Column_Styles[2].BackColor = Color.White;

            if (hasAuthorData)
                gridPanel.Style.Column_Styles[3].Width = SMaRT_UserSettings.View_Item_Group_Form_Author_Width;
            else
                gridPanel.Style.Column_Styles[3].Visible = false;

            if (hasPublisherData)
                gridPanel.Style.Column_Styles[4].Width = SMaRT_UserSettings.View_Item_Group_Form_Publisher_Width;
            else
                gridPanel.Style.Column_Styles[4].Visible = false;

            if ( hasDateData)
                gridPanel.Style.Column_Styles[5].Width = SMaRT_UserSettings.View_Item_Group_Form_Date_Width;
            else
                gridPanel.Style.Column_Styles[5].Visible = false;

            if (hasLevel1Data)
                gridPanel.Style.Column_Styles[6].Width = SMaRT_UserSettings.View_Item_Group_Form_Level1_Width;
            else
                gridPanel.Style.Column_Styles[6].Visible = false;

            gridPanel.Style.Column_Styles[6].Text_Alignment = HorizontalAlignment.Left;
            gridPanel.Style.Column_Styles[7].Visible = false;
            if (hasLevel2Data)
                gridPanel.Style.Column_Styles[8].Width = SMaRT_UserSettings.View_Item_Group_Form_Level2_Width;
            else
                gridPanel.Style.Column_Styles[8].Visible = false;
            gridPanel.Style.Column_Styles[8].Text_Alignment = HorizontalAlignment.Left;
            gridPanel.Style.Column_Styles[9].Visible = false;
            if (hasLevel3Data)
                gridPanel.Style.Column_Styles[10].Width = SMaRT_UserSettings.View_Item_Group_Form_Level3_Width;
            else
                gridPanel.Style.Column_Styles[10].Visible = false;
            gridPanel.Style.Column_Styles[10].Text_Alignment = HorizontalAlignment.Left;
            gridPanel.Style.Column_Styles[11].Visible = false;
            gridPanel.Style.Column_Styles[12].Width = 60;
            gridPanel.Style.Column_Styles[12].Text_Alignment = HorizontalAlignment.Left;
            gridPanel.Style.Column_Styles[12].BackColor = Color.White;
            gridPanel.Style.Column_Styles[13].Width = 120;
            gridPanel.Style.Column_Styles[13].BackColor = Color.White;
            gridPanel.Style.Column_Styles[14].Width = 100;
            gridPanel.Style.Column_Styles[14].BackColor = Color.White;
            gridPanel.Style.Column_Styles[15].Width = 125;
            gridPanel.Style.Column_Styles[16].Width = 80;
            gridPanel.Style.Column_Styles[17].Visible = false;
            gridPanel.Style.Column_Styles[18].Visible = false;
            gridPanel.Style.Column_Styles[19].Visible = false;

            // Set some sort values
            gridPanel.Style.Column_Styles[2].Ascending_Sort = "SortTitle ASC, Level1_Index ASC, Level2_Index ASC, Level3_Index ASC, SortDate ASC";
            gridPanel.Style.Column_Styles[2].Descending_Sort = "SortTitle DESC, Level1_Index DESC, Level2_Index DESC, Level3_Index DESC, SortDate DESC";
            gridPanel.Style.Column_Styles[5].Ascending_Sort = "SortDate ASC, PubDate ASC";
            gridPanel.Style.Column_Styles[5].Descending_Sort = "SortDate DESC, PubDate DESC";
            gridPanel.Style.Column_Styles[6].Ascending_Sort = "Level1_Index ASC, Level2_Index ASC, Level3_Index ASC, SortDate ASC";
            gridPanel.Style.Column_Styles[6].Descending_Sort = "Level1_Index DESC, Level2_Index DESC, Level3_Index DESC, SortDate DESC";
            gridPanel.Style.Column_Styles[8].Ascending_Sort = "Level2_Index ASC, Level3_Index ASC";
            gridPanel.Style.Column_Styles[8].Descending_Sort = "Level2_Index DESC, Level3_Index DESC";

            // Add the event to the grid panel
            gridPanel.Double_Clicked += gridPanel_Double_Clicked;

            // Add the context menu
            gridPanel.Set_Context_Menus(null, contextMenu1);

            // Add the object to print
            gridPrinter = new CustomGrid_Printer(gridPanel, printDocument1);

            // Determine if any ALEPH, OCLC, AUTHOR, or PUBLISHER data is present
            bool checkingAuthor = true;
            bool checkingPublisher = true;
            foreach (DataRow thisRow in displayTable.Rows)
            {
                if (checkingAuthor)
                {
                    if (thisRow[returnAuthorColumn].ToString().Trim().Length > 0)
                    {
                        checkingAuthor = false;
                    }
                }

                if (checkingPublisher)
                {
                    if (thisRow[returnPublisherColumn].ToString().Trim().Length > 0)
                    {
                        checkingPublisher = false;
                    }
                }

                if ((!checkingAuthor) && (!checkingPublisher))
                    break;
            }

            // Set the visibility of the columns based on the data
            gridPanel.Style.Column_Styles[3].Visible = !checkingAuthor;
            gridPanel.Style.Column_Styles[4].Visible = !checkingPublisher;

            // Set focus
            gridPanel.Focus();
        }