By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

Panel Scrollbars Problem

P: 26
Hi all,

I am using panel with autoscroll = true in C#

I have added dataGridView control inside panel.

When the height and width of dataGridView increases and becomes more than panel size, scrollbars of panel are enabled.

When i scroll using any scrollbar and click on the dataGridView which is inside panel, the position of the scrolled scrollbar changes automatically and scrollbars goes to start position.

can anyone tell me how to solve this problem???
Dec 5 '08 #1
Share this Question
Share on Google+
5 Replies

P: 61
Expand|Select|Wrap|Line Numbers
  1. private void panel1_Scroll(object sender, ScrollEventArgs e)
  2. {
  3.   dataGridView1.Focus();
  4. }
Dec 5 '08 #2

P: 26
Thank you Ramk, that solved the problem.
Dec 8 '08 #3

P: 26

Actually the above approach solved the problem to some extent.

whenever i click on DataGridView after scrolling, the problem is not there, but now if i leave the scrollbars in any position other than starting position and the focus is shifted to other control say ComboBox, now again when i click on DataGridView inside panel, scrollbars move to original position.

can you please suggest something

Dec 10 '08 #4

Expert Mod 5K+
P: 9,731
Have you considered adding scroll bars to the DataGridView instead of the Panel?
Dec 10 '08 #5

P: 26
Hi Frinavale,

Actually I am not using DataGridView as it is, I have created User Control "Table", in which user will be allowed to merge rows and columns. so I am painting the whole DataGridView in CellPainting event.

This "Table" control is added in other application on panel for which AutoScroll is enabled.

so I set the Width and Height of DataGridView equal to sum of Widths of columns and that of heights of rows respectively.

now here the above mentioned problem comes into picture.

Anyway I have found the solution to this problem, i am handling the MouseDown and MouseClick events for DataGridView in which i m setting the position of the scrollbars for the panel.

Thanks for all your suggestions :)

Dec 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.