Get and Set the position of a ListBox scroll bar

  • Thread starter lagu2653 via DotNetMonster.com
  • Start date
L

lagu2653 via DotNetMonster.com

Is it possible to set the position of a ListBox scroll bar in C#. I've
inherited the ListBox class. I get a NullReferenceException when I try to do
this:

IEnumerator i = listBox1.Controls.GetEnumerator();
i.MoveNext();
MessageBox.Show(string.Format("i.Current.Visible.ToString() = {0}", (
(ScrollBar)i.Current).Visible.ToString()));

i.Current returns NULL. It works for a datagrid. The controls collection is
empty.
 
A

Alex Yakhnin

It works for DataGrid because it's a managed control, wereas ListBox is
wrapper around a native one. To hide a scroll bar in the ListBox, you'd need
to use P/Invoke by changing its window style bits.
Or the other workaround could be placing the ListBox inside of a panel and
making the panel's width smaller on the width of the scroll bar.

-Alex
 
L

lagu2653 via DotNetMonster.com

I don't want to hide the scroll bar. I want to scroll it into a certain
position. I want to set the value to e.g.

Scrollbar.value = 247;

Can you do that by P/Invoking something. Where can I find a specification for
the DLLs, which I need to P/Invoke?

/Lars

Alex said:
It works for DataGrid because it's a managed control, wereas ListBox is
wrapper around a native one. To hide a scroll bar in the ListBox, you'd need
to use P/Invoke by changing its window style bits.
Or the other workaround could be placing the ListBox inside of a panel and
making the panel's width smaller on the width of the scroll bar.

-Alex

--
Alex Yakhnin, Device Application Developer MVP
http://blog.opennetcf.org/ayakhnin
Is it possible to set the position of a ListBox scroll bar in C#. I've
inherited the ListBox class. I get a NullReferenceException when I try to
[quoted text clipped - 9 lines]
is
empty.
 
L

lagu2653 via DotNetMonster.com

I don't want to hide the scroll bar. I want to scroll it into a certain
position. I want to set the value to e.g.

Scrollbar.value = 247;

Can you do that by P/Invoking something. Where can I find a specification for
the DLLs, which I need to P/Invoke?

/Lars

Alex said:
It works for DataGrid because it's a managed control, wereas ListBox is
wrapper around a native one. To hide a scroll bar in the ListBox, you'd need
to use P/Invoke by changing its window style bits.
Or the other workaround could be placing the ListBox inside of a panel and
making the panel's width smaller on the width of the scroll bar.

-Alex

--
Alex Yakhnin, Device Application Developer MVP
http://blog.opennetcf.org/ayakhnin
Is it possible to set the position of a ListBox scroll bar in C#. I've
inherited the ListBox class. I get a NullReferenceException when I try to
[quoted text clipped - 9 lines]
is
empty.
 

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