473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ListBox VScrollBar ???

I have a ListBox on my form and wand to do auto scrolling, I can do that by:
myListBox.ClearSelected();
OutputListBox.SelectedIndex = myListBox.Items.Count - 1;

But it causes to unselect all selected items, so I wish do that by moving
the vertical scroll bar, imbedded in the ListBox.
But I couldn’t find a way to get the ListBox vertical scroll bar.
Can anybody show how to obtain it and how to make move/scroll??

--
Regards
Sharon G.
Nov 16 '05 #1
4 8121
Override ListBox class as following :

public class ListBoxScroll:ListBox {
private const int SB_HORZ=0;
private const int SB_VERT=1;
[System.Runtime.InteropServices.DllImport("user32.d ll")]
private static extern int GetScrollPos(int hWnd,int nBar);
[System.Runtime.InteropServices.DllImport("user32.d ll")]
private static extern int SetScrollPos(int hWnd,int nBar,int nPos,bool
bRedraw);
public int HScrollPos {
get {return GetScrollPos((int)Handle,SB_HORZ);}
set {SetScrollPos((int)Handle,SB_HORZ,value,true);}
}
public int VScrollPos {
get {return GetScrollPos((int)Handle,SB_VERT);}
set {SetScrollPos((int)Handle,SB_VERT,value,true);}
}
}

You have now two new members, called HScrollPos et VScrollPos. The last is
the one you are looking for.

Hope it helps,
Ludovic SOEUR.
"Sharon" <Sh****@discussions.microsoft.com> a écrit dans le message de
news:AF**********************************@microsof t.com...
I have a ListBox on my form and wand to do auto scrolling, I can do that by: myListBox.ClearSelected();
OutputListBox.SelectedIndex = myListBox.Items.Count - 1;

But it causes to unselect all selected items, so I wish do that by moving
the vertical scroll bar, imbedded in the ListBox.
But I couldn't find a way to get the ListBox vertical scroll bar.
Can anybody show how to obtain it and how to make move/scroll??

--
Regards
Sharon G.

Nov 16 '05 #2
Thanks Ludovic,
But it does not work; the set does not work as expected.
I do succeed to move the scroll to the bottom of it range but does not move
the items of the ListBox, and off course this is what it’s all for.

Any idea ?
Nov 16 '05 #3
Funny control (it keeps in memory the scrollbar location to draw its items).
There is another way to let it believes that the user changed the scrollbar
location, using the WM_VSCROLL message. Use the following lines instead :

public class ListBoxScroll:ListBox {
private const int WM_VSCROLL=0x0115;
private const int SB_VERT=1;
[System.Runtime.InteropServices.DllImport("user32.d ll")]
private static extern int GetScrollPos(int hWnd,int nBar);
[System.Runtime.InteropServices.DllImport("user32.d ll")]
public static extern int SendMessage(int hWnd,uint Msg,int wParam,int
lParam);
public int VScrollPos {
get {return GetScrollPos((int)Handle,SB_VERT);}
set
{SendMessage((int)Handle,WM_VSCROLL,((value<0?0:va lue&255)<<16)+(int)ScrollE
ventType.ThumbPosition,0);}
}
}

If think this time it is what you were looking for.

Hope it helps.

Ludovic SOEUR.

"Sharon" <Sh****@discussions.microsoft.com> a écrit dans le message de
news:D9**********************************@microsof t.com...
Thanks Ludovic,
But it does not work; the set does not work as expected.
I do succeed to move the scroll to the bottom of it range but does not move the items of the ListBox, and off course this is what it's all for.

Any idea ?

Nov 16 '05 #4
Well , I found an easier way:

myListBox.TopIndex = myListBox.Items.Add("the string to add");

This way it does auto scrolling as I want him to.

Thanks
Sharon
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
0
by: Gawelek | last post by:
I would like to "cheat" VScrollBar in DataGrid. That means I want to link for example DataTable with 50 rows to DataGrid. But I want, that VScrollBar looks as if DataTable contains for example...
1
by: Durand | last post by:
Hi all, I'm trying to create a vScrollBar with a dynamic value. When I change the maximum value inside a method, it works inside a method, but when I leave this method the maximum value returns...
1
by: Dmitri Shvetsov | last post by:
Hi All, Did somebody play with vScrollBar in C#? I've got a small trouble. When I assign the Maximum value and try to move the slider of the vScrollBar to a maximum position I can't get the...
2
by: Hans [DiaGraphIT] | last post by:
Hi! In a windowsapplication i have a datagrid where I dont want the vertical scrollbar to be visible. I can't find HorizontalScrollBar and VerticalScrollBar properties anywhere. I've tried...
0
by: bleedledeep | last post by:
I have a DataGrid that ends up with a VScrollBar due to the number of rows, and the behavior I want is for the bottom-most row of the DataGrid to be shown, i.e., I want the VScrollBar all the way...
1
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the System.Windows.Forms.VScrollBar on my form. I'm handling VScrollBar Scroll event. I want to handle the Up, Down, PageUp PageDown keys for this VScrollBar, but when I register to...
0
by: Longkhi | last post by:
Hi everybody. I have quite a problem with the vscrollbar component. The control I'm using has a built-in scrollbar, but I have 5 of those controls, and I would like to bind the external...
1
by: eBob.com | last post by:
I have two apps, both developed using the same VBE, and both having a VScrollBar, but the two VScrollBars have very different styles. (In the screen shot, which I had hoped to attach but can't,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.