From: Mesalem on
I have a datagrid derived class where i want to scroll the horizontal scroll
bar to the right. i tried the following code:

HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
sb.Value=5;

but i received a NullReferenceException in System.Windows.Forms.DataGrid.Dll,
I tried the following code and the same exception happened


HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);

System.Reflection.PropertyInfo pi=sb.GetType().GetProperty
("Value",BindingFlags.Public | BindingFlags.Instance );

pi.SetValue (sb,90,null);


any suggestions??



From: Sergey Bogdanov on
Instead of base.GetType().GetField(...) use:
typeof(DataGrid).GetField(...).

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Mesalem wrote:
> I have a datagrid derived class where i want to scroll the horizontal scroll
> bar to the right. i tried the following code:
>
> HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
> BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
> sb.Value=5;
>
> but i received a NullReferenceException in System.Windows.Forms.DataGrid.Dll,
> I tried the following code and the same exception happened
>
>
> HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
> BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
>
> System.Reflection.PropertyInfo pi=sb.GetType().GetProperty
> ("Value",BindingFlags.Public | BindingFlags.Instance );
>
> pi.SetValue (sb,90,null);
>
>
> any suggestions??
>
>
>
From: Mesalem on
i found the bug it was initialization problem, thanks for the reply
Does anyone know how to do this in a listview??

"Sergey Bogdanov" wrote:

> Instead of base.GetType().GetField(...) use:
> typeof(DataGrid).GetField(...).
>
> Best regards,
> Sergey Bogdanov
> http://www.sergeybogdanov.com
>
>
> Mesalem wrote:
> > I have a datagrid derived class where i want to scroll the horizontal scroll
> > bar to the right. i tried the following code:
> >
> > HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
> > BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
> > sb.Value=5;
> >
> > but i received a NullReferenceException in System.Windows.Forms.DataGrid.Dll,
> > I tried the following code and the same exception happened
> >
> >
> > HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
> > BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
> >
> > System.Reflection.PropertyInfo pi=sb.GetType().GetProperty
> > ("Value",BindingFlags.Public | BindingFlags.Instance );
> >
> > pi.SetValue (sb,90,null);
> >
> >
> > any suggestions??
> >
> >
> >
>
From: Sergey Bogdanov on
You may consider EnsureVisible method and if you would like to scroll to
the end of the list then call the method with "listView.Items.Count - 1".

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Mesalem wrote:
> i found the bug it was initialization problem, thanks for the reply
> Does anyone know how to do this in a listview??
>
> "Sergey Bogdanov" wrote:
>
>
>>Instead of base.GetType().GetField(...) use:
>>typeof(DataGrid).GetField(...).
>>
>>Best regards,
>>Sergey Bogdanov
>>http://www.sergeybogdanov.com
>>
>>
>>Mesalem wrote:
>>
>>>I have a datagrid derived class where i want to scroll the horizontal scroll
>>>bar to the right. i tried the following code:
>>>
>>>HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
>>>BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
>>> sb.Value=5;
>>>
>>>but i received a NullReferenceException in System.Windows.Forms.DataGrid.Dll,
>>>I tried the following code and the same exception happened
>>>
>>>
>>>HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
>>>BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
>>>
>>>System.Reflection.PropertyInfo pi=sb.GetType().GetProperty
>>>("Value",BindingFlags.Public | BindingFlags.Instance );
>>>
>>>pi.SetValue (sb,90,null);
>>>
>>>
>>>any suggestions??
>>>
>>>
>>>
>>
From: Mesalem on
this method will scroll the listview top or down (vertical),
what about scrolling to the right or the left (horizonal)??


"Sergey Bogdanov" wrote:

> You may consider EnsureVisible method and if you would like to scroll to
> the end of the list then call the method with "listView.Items.Count - 1".
>
> Best regards,
> Sergey Bogdanov
> http://www.sergeybogdanov.com
>
>
> Mesalem wrote:
> > i found the bug it was initialization problem, thanks for the reply
> > Does anyone know how to do this in a listview??
> >
> > "Sergey Bogdanov" wrote:
> >
> >
> >>Instead of base.GetType().GetField(...) use:
> >>typeof(DataGrid).GetField(...).
> >>
> >>Best regards,
> >>Sergey Bogdanov
> >>http://www.sergeybogdanov.com
> >>
> >>
> >>Mesalem wrote:
> >>
> >>>I have a datagrid derived class where i want to scroll the horizontal scroll
> >>>bar to the right. i tried the following code:
> >>>
> >>>HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
> >>>BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
> >>> sb.Value=5;
> >>>
> >>>but i received a NullReferenceException in System.Windows.Forms.DataGrid.Dll,
> >>>I tried the following code and the same exception happened
> >>>
> >>>
> >>>HScrollBar sb = (HScrollBar)base.GetType().GetField("m_sbHorz",
> >>>BindingFlags.NonPublic|BindingFlags.GetField|BindingFlags.Instance).GetValue(this);
> >>>
> >>>System.Reflection.PropertyInfo pi=sb.GetType().GetProperty
> >>>("Value",BindingFlags.Public | BindingFlags.Instance );
> >>>
> >>>pi.SetValue (sb,90,null);
> >>>
> >>>
> >>>any suggestions??
> >>>
> >>>
> >>>
> >>
>