locked
Scroll DataGridView while dragging cell over frozen column RRS feed

  • Question

  • Hi All,

    I have a problem when dragging a DataGridViewCell in a DataGridView (DGV). The first three columns of my DGV are frozen and when dragging a cell over these frozen columns, I would like the DGV to scroll to the left. Otherwise the user has to drop the cell, scroll manually and then drag again. If there are a large number of columns, this is not feasible.

    Does anyone know how to scroll a DGV in code? I can scroll to the right, as I can increment the FirstDisplayedScrollingColumnIndex property of the DGV. However, this does not work scrolling left, as there are
    frozen columns.

    Please let me know if more information is needed.

    Any feedback is much appreciated.

    Cheers,
    Lars
    Tuesday, June 10, 2008 2:56 AM

Answers

  • You can judge the value of the FirstDisplayedScrollingColumnIndex property first,as

    Code Snippet

     

            private void button1_Click(object sender, EventArgs e)

            {

                if (this.dataGridView1.FirstDisplayedScrollingColumnIndex > 3)

                {

                    this.dataGridView1.FirstDisplayedScrollingColumnIndex--;

                }

            }

     

            private void button2_Click(object sender, EventArgs e)

            {

                if (this.dataGridView1.FirstDisplayedScrollingColumnIndex
                    < this.dataGridView1.ColumnCount)

                {

                    this.dataGridView1.FirstDisplayedScrollingColumnIndex++;

                }

            }

     

     

     

    Friday, June 13, 2008 7:41 AM