Connecting Tech Pros Worldwide Forums | Help | Site Map

Panel Scrollbars Problem

Newbie
 
Join Date: Dec 2008
Posts: 22
#1: Dec 5 '08
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???
Member
 
Join Date: Nov 2008
Posts: 58
#2: Dec 5 '08

re: Panel Scrollbars Problem


Expand|Select|Wrap|Line Numbers
  1. private void panel1_Scroll(object sender, ScrollEventArgs e)
  2. {
  3.   dataGridView1.Focus();
  4. }
Newbie
 
Join Date: Dec 2008
Posts: 22
#3: Dec 8 '08

re: Panel Scrollbars Problem


Thank you Ramk, that solved the problem.
Newbie
 
Join Date: Dec 2008
Posts: 22
#4: Dec 10 '08

re: Panel Scrollbars Problem


Hi,

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

Regards
Abhishek
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,083
#5: Dec 10 '08

re: Panel Scrollbars Problem


Have you considered adding scroll bars to the DataGridView instead of the Panel?
Newbie
 
Join Date: Dec 2008
Posts: 22
#6: Dec 11 '08

re: Panel Scrollbars Problem


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 :)

Regards
Abhishek
Reply