Ejemplo n.º 1
0
        private void UpdateLocation()
        {
            int startRow = currentPage * rowsPerPage + 1;
            int lastRow  = startRow + rowsPerPage - 1;

            if (lastRow > count)
            {
                lastRow = count;
            }

            filterToolStripButton.Checked     = IsFiltered;
            filterToolStripButton.ToolTipText = IsFiltered ? filter.ToString() : "Filter";
            sortToolStripButton.Checked       = IsSorted;
            sortToolStripButton.ToolTipText   = IsSorted ? sort.ToString() : "Sort";

            if (IsFiltered)
            {
                locationLabel.Text = String.Format("{0:0000} to {1:0000} of {2:0000}*", startRow, lastRow, count);
            }
            else
            {
                locationLabel.Text = String.Format("{0:0000} to {1:0000} of {2:0000}", startRow, lastRow, count);
            }

            if (currentPage == 0)
            {
                firstButton.Enabled = false;
                prevButton.Enabled  = false;
            }
            else
            {
                firstButton.Enabled = true;
                prevButton.Enabled  = true;
            }

            if (lastRow == count)
            {
                nextButton.Enabled = false;
                lastButton.Enabled = false;
                dataGridView.AllowUserToAddRows = true;
            }
            else
            {
                nextButton.Enabled = true;
                lastButton.Enabled = true;
                dataGridView.AllowUserToAddRows = false;
            }

            dataGridView.StartRowNumber = startRow;
        }
Ejemplo n.º 2
0
        private void filterToolStripButton_Click(object sender, EventArgs e)
        {
            if (!CanContinue())
            {
                return;
            }
            using (FilterDialog filterDialog = new FilterDialog(this.filter.Clone())) {
                FormExtensions.DownPositionate(filterDialog, filterToolStripButton, this);
                if (filterDialog.ShowDialog(this) == DialogResult.OK)
                {
                    TableFilter lastGood = this.filter;
                    this.filter = filterDialog.Filter;

                    if (IsFiltered)
                    {
                        this.currentPage = 0;
                        this.filterToolStripButton.Checked = true;
                    }
                    else
                    {
                        this.filterToolStripButton.Checked = false;
                    }
                    this.filterToolStripButton.ToolTipText = IsFiltered ? filter.ToString() : "Filter";

                    try {
                        this.UpdateDataSet();
                    } catch (Exception ex) {
                        this.filter = lastGood;
                        MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK);
                        this.UpdateDataSet();
                    }
                }
                else
                {
                    if (this.refreshDataNeeded)
                    {
                        this.UpdateDataSet();
                    }
                }
            }
        }