private void dgView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            // sorting is handle by this event handler
            //dgView.Columns.Cast<DataGridViewColumn>().ToList().ForEach(n => n.HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.None);

            string strSortCol = this.dgView.Columns[e.ColumnIndex].Name;

            if (strPrevSortCol.Trim().ToUpper() != strSortCol.Trim().ToUpper())
            {
                this.dgView.Columns[strPrevSortCol].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.None;
                strPrevSortCol = strSortCol;
                strSortOrder = "ASC";
            }

            if (this.dgView.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection == System.Windows.Forms.SortOrder.Ascending)
            {
                this.dgView.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Descending;
                strSortOrder = "DESC";
            }
            else if (this.dgView.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection == System.Windows.Forms.SortOrder.Descending)
            {
                this.dgView.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Ascending;
                strSortOrder = "ASC";
            }
            else
            {
                if (strSortOrder == "ASC")
                    this.dgView.Columns[strSortCol].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Ascending;
                else
                    this.dgView.Columns[strSortCol].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Descending;

            }

            dgView.Rows.Clear();

            DataRetriever retriever = new DataRetriever(ConnectionString, TableName, Filters , strSortCol + " " + strSortOrder);
            memoryCache = new Cache(retriever, PageSize);
            this.dgView.RowCount = retriever.RowCount;
            dgView.Refresh();
        }
        public void LoadData()
        {
            // this function will load data into data table
            dgView.Rows.Clear();
            dgView.Refresh();
            dgView.Columns.Clear();
            dgView.DataSource = null;

            try
            {
                DataRetriever retriever = null;
                retriever = new DataRetriever(ConnectionString, TableName, Filters, SortColumn + " " + SortOrder);
                memoryCache = new Cache(retriever, PageSize);
                memoryCache.CacheExpire += OnCacheExpire;
                memoryCache.CacheFilled += OnCacheFilled;
                retriever.Columns.Cast<DataColumn>().ToList().ForEach(n => dgView.Columns.Add(n.ColumnName, n.ColumnName));
                this.dgView.RowCount = retriever.RowCount;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection could not be established. " + "Verify that the connection string is valid.");
                Application.Exit();
            }

            // Adjust the column widths based on the displayed values.
            this.dgView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
            /*
            // set the sorting glyph initially when data load
            if (strSortOrder == "ASC")
            {
                this.dgView.Columns[strSortCol].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Ascending;
            }
            else
            {
                this.dgView.Columns[strSortCol].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Descending;
            }
             * */
        }