Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Problem with scrollbars of panel in C#
 

Problem with scrollbars of panel in C#

Hi all,

I am using panel with autoscroll = true.

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???
Kulabhishek  Friday, December 05, 2008 9:25 AM
Hi Kira,

I have found the solution to this problem, I am handling the MouseDown and MouseClick events for DataGridView in which I am setting the position of the scrollbars for the panel, this position was saved in "Panel_Scroll" event.

Thanks for all your suggestions :)

Regards
Abhishek
  • Marked As Answer byKulabhishek Thursday, December 11, 2008 5:23 AM
  •  
Kulabhishek  Thursday, December 11, 2008 5:22 AM

Hi AOL-IR,

I confuse why the size of your DataGridView in the panel will increase? DataGridView has scroll bar by default. When the count of the rows in DataGridView is great, it will show scroll bar automatically. Can you tell me the reason why you want to enlarge the DataGridView and let the panel show scroll bar?

Sincerely,

Kira Qian

Kira Qian  Monday, December 08, 2008 7:40 AM
Hi Kira,

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.

i have tried like this :

  1. privatevoidpanel1_Scroll(objectsender,ScrollEventArgse)
  2. {
  3. dataGridView1.Focus();
  4. }

but actually the above approach solves 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
Kulabhishek  Wednesday, December 10, 2008 12:14 PM
Hi Kira,

I have found the solution to this problem, I am handling the MouseDown and MouseClick events for DataGridView in which I am setting the position of the scrollbars for the panel, this position was saved in "Panel_Scroll" event.

Thanks for all your suggestions :)

Regards
Abhishek
  • Marked As Answer byKulabhishek Thursday, December 11, 2008 5:23 AM
  •  
Kulabhishek  Thursday, December 11, 2008 5:22 AM
That is still a problem in many other scenarios. You can lose focus and gain focus of usercontrol with many events like minimizing and maximizing the application, popup dialogs or accessing the menu items. Why does panel re-set scroll position? How can we sovle this problem.

The same issue does not happen for controls derived from Picturebox.
subra
Subrahmanya_kadiyala  Tuesday, March 03, 2009 10:55 PM

You can use google to search for other answers

Custom Search

More Threads

• display sequential images on a window form
• UI Patterns
• Audit Trail using C#.Net - Winforms
• Automation interface
• always can't connect Terrarium server
• Can´t logon using TaskVision for PPC2002
• Naka and Mari - Is Terrarium fun over ?
• Error on compiling and running taskvision
• XPander nesting
• Another question