Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Avoid scrolling in DataGriView
 

Avoid scrolling in DataGriView

Hi,

I want the DataGridView to show the scroll bars when applicable but when the scoll bars are moved I want the Rows/Columns should not move. Is there any way to acheive this, I looked at the OnScroll but its not a CancelEventArgs.

Please help!
Adii http://adiigeek.blogspot.com/
AdiiS  Wednesday, July 22, 2009 5:32 AM

Hi AdiiS,

We need to create our own DataGridView and override the OnScroll method. In the method, we can set the new value equal to the old value to avoid rows/columns moving. This is the code snippet:
public class MyDataGridView : DataGridView

{

public MyDataGridView()

{

//Enable both scrollbars.

this.ScrollBars = ScrollBars.Both;

}

protected override void OnScroll(ScrollEventArgs e)

{

//Set the new value equal to old value to avoid moving.

e.NewValue = e.OldValue;

base.OnScroll(e);

}

}

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, July 23, 2009 6:13 AM

Hi AdiiS,

Could you please let me know if my reply helps you? If you still have problems, please feel free to tell me.

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, July 27, 2009 3:52 AM

You can use google to search for other answers

Custom Search

More Threads

• Find a string from DatagridView and Delete it when no string found it will throw messages
• BindingSource.Find throws exception on empty DataSet
• Adding Item dynamically into the DataGridViewComboboxColumn
• How to programmatically change a bound combobox
• Beginner Formatting Questions
• Delete
• How to add a new row as header?
• Web Services as datasources
• how to work with datagrid?
• getting column info from previous row and loading it into textbox using button