Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Datagridview doesn't horizontally scroll to the end

$
0
0

I have a datagridview control that I programatically scroll horizontally and vertically from a search box on top. It scrolls down to the bottom very nicely but it doesn't scroll all the way to right it stops a little before and I'm not sure why?

Below is the scrolling code:

        privatevoid txtSearch_KeyDown(object sender,KeyEventArgs e)

        {

            isKeyPress =true;

           if (e.KeyCode.Equals(Keys.Left))

            {

                dgvList.MoveDataGridViewColumnLeft();

               return;

            }

           if (e.KeyCode.Equals(Keys.Right))

            {

                dgvList.MoveDataGridViewColumnRight();

               return;

            }

           if (e.KeyCode.Equals(Keys.Up))

            {

                bs.MovePrevious();

               return;

            }

           if (e.KeyCode.Equals(Keys.Down))

            {

               if (dgvList.CurrentCell == null) dgvList[0, 0].Selected = true;

               else

                {

                    bs.MoveNext();

                }

               return;

            }

        }

       publicstatic void MoveDataGridViewColumnLeft(this DataGridView sender)

        {

           try

            {

               int ColumnCount = sender.ColumnCount - 1;

               int ColumnIndex = sender.CurrentCell.ColumnIndex;

               int RowIndex = sender.CurrentCell.RowIndex;

               if (ColumnIndex - 1 > -1)

                {

                   int ProposedColumnIndex = ColumnIndex - 1;

                   int NewColumnIndex = 0;

                   if (sender.GetLastVisibleColumn(ref NewColumnIndex))

                    {

                       if (ProposedColumnIndex <= NewColumnIndex)

                        {

                            sender.CurrentCell = sender[ProposedColumnIndex, RowIndex];

                        }

                       else

                        {

                            sender.CurrentCell = sender[ColumnIndex - 1, RowIndex];

                        }

                    }

                }

            }

           catch

            {

            }

        }

       publicstatic void MoveDataGridViewColumnRight(this DataGridView sender)

        {

           try

            {

               int ColumnCount = sender.ColumnCount - 1;

               int ColumnIndex = sender.CurrentCell.ColumnIndex;

               int RowIndex = sender.CurrentCell.RowIndex;

               if (ColumnIndex + 1 <= ColumnCount)

                {

                   int ProposedColumnIndex = ColumnIndex + 1;

                   int NewColumnIndex = 0;

                   if (sender.GetLastVisibleColumn(ref NewColumnIndex))

                    {

                       if (ProposedColumnIndex > NewColumnIndex)

                        {

                            sender.CurrentCell = sender[NewColumnIndex, RowIndex];

                        }

                       else

                        {

                            sender.CurrentCell = sender[ColumnIndex+ 1, RowIndex];

                        }

                    }

                }

            }

           catch

            {

            }

        }

I use this code in numerous places and it works fine. Just in one case it doesn't work.


Debra has a question


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>