Catching scroll event for datagrid

J

jamie

I notice that there is no scroll event for a datagrid in the
compactframework. How can I figure out that a scroll has taken place?

The issue I have is I have a floating textbox overtop of the datagrid column
that I need to reposition and change it's text value to match the selected
column. This works fine when currentcellchanged fires however scrolling
doesn't change the currentcell.

It appears that the textbox doesn't lose focus when the scroll bar is
selected so thats out. Any other ideas?

All I want to do is stop the textbox from being visible when the datagrid is
scrolled since currentcellchanged can remake it visible when it repositions
it.
 
B

Bipin_Expert

Hi,
I access datagrid scrollbars using System.Reflection , by defining
2 scrollbars:

Private vsb As VScrollBar
Private hsb As HScrollBar

and then changing their type to scrollbars of a DataGrid
(dgridMeters here):

vsb = CType(dgridMeters.GetType.GetField("m_sbVert",
BindingFlags.NonPublic Or BindingFlags.GetField Or
BindingFlags.Instance).GetValue(dgridMeters), VScrollBar)
hsb = CType(dgridMeters.GetType.GetField("m_sbHorz",
BindingFlags.NonPublic Or BindingFlags.GetField Or
BindingFlags.Instance).GetValue(dgridMeters), HScrollBar)

I think you can then access vsb.ValueChanged and hsb.ValueChanged
events if you declare them WithEvents and create a procedure to handle
the events. However, I do enable/disable datagrid scrollbars on SIP
enable/disable and haven't tried it out. Please leave a comment if it
works. I am using VS2005 and .NET CF2SP1

Best Regards,
Bipin Kesharwani
(Developer)

Palewar Techno Solutions
Windows Mobile & Palm Development
Nagpur, India

www.palewar.com
 
J

jamie

Excellent. I had never tried using Reflection before. I may end up using
this to fix some other little things that annoy me as well.
For anyone that cares here's the solution in C# the VB Or threw me for a
bit.

I just threw this in InitializeComponent() rowGrid is the dataGrid in
question, rowGrid_Scroll handles the event of course which in this case is I
simply make the textbox.visble = false; and of course you need to add using
System.Reflection;

//

// Vertical scroll bar

//

vsb = (VScrollBar)rowGrid.GetType().GetField("m_sbVert",
BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(rowGrid);

this.vsb.ValueChanged += new System.EventHandler(this.rowGrid_Scroll);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top