473,769 Members | 4,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox VScrollBar ???

I have a ListBox on my form and wand to do auto scrolling, I can do that by:
myListBox.Clear Selected();
OutputListBox.S electedIndex = 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 8136
Override ListBox class as following :

public class ListBoxScroll:L istBox {
private const int SB_HORZ=0;
private const int SB_VERT=1;
[System.Runtime. InteropServices .DllImport("use r32.dll")]
private static extern int GetScrollPos(in t hWnd,int nBar);
[System.Runtime. InteropServices .DllImport("use r32.dll")]
private static extern int SetScrollPos(in t hWnd,int nBar,int nPos,bool
bRedraw);
public int HScrollPos {
get {return GetScrollPos((i nt)Handle,SB_HO RZ);}
set {SetScrollPos(( int)Handle,SB_H ORZ,value,true) ;}
}
public int VScrollPos {
get {return GetScrollPos((i nt)Handle,SB_VE RT);}
set {SetScrollPos(( int)Handle,SB_V ERT,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****@discuss ions.microsoft. com> a écrit dans le message de
news:AF******** *************** ***********@mic rosoft.com...
I have a ListBox on my form and wand to do auto scrolling, I can do that by: myListBox.Clear Selected();
OutputListBox.S electedIndex = 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:L istBox {
private const int WM_VSCROLL=0x01 15;
private const int SB_VERT=1;
[System.Runtime. InteropServices .DllImport("use r32.dll")]
private static extern int GetScrollPos(in t hWnd,int nBar);
[System.Runtime. InteropServices .DllImport("use r32.dll")]
public static extern int SendMessage(int hWnd,uint Msg,int wParam,int
lParam);
public int VScrollPos {
get {return GetScrollPos((i nt)Handle,SB_VE RT);}
set
{SendMessage((i nt)Handle,WM_VS CROLL,((value<0 ?0:value&255)<< 16)+(int)Scroll E
ventType.ThumbP osition,0);}
}
}

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

Hope it helps.

Ludovic SOEUR.

"Sharon" <Sh****@discuss ions.microsoft. com> a écrit dans le message de
news:D9******** *************** ***********@mic rosoft.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.TopIn dex = 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
7873
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 allso subclassed the window and do see all kinds of WS_??? messages coming by. But now I'm stuck :-\ I've got *no* idea what to do next, and all my searching on the web leads me
0
1133
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 100 or 1000 rows. Is it possible to do ? I tried by Maximum properties, but it seems not to work. Gawel
1
1273
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 to previous value. My vScrollBar is not declared inside any method. Thanks Durand
1
5160
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 maximum value from a vScrollBar.Value. I can assume that to correct this problem is easy. I'm sure that's it's a bug, the developers didn't think about the width of the slider and this width is excluded from the vScrollBar total length, so we're...
2
1984
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 to create controls for this... without luck. Here is the code I'm using. Please tell me what I'm doing wrong. this.InitializeScrollBar(DataGrid1)
0
1271
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 to the bottom (maximum). I grab and set the VScrollBar using the following: if ( historyDataGrid.Controls is VScrollBar ) { VScrollBar vsb = (VScrollBar)historyDataGrid.Controls;
1
2399
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 the keyDown and KeyPress events, it never gets there. So I also handled the key events of the form and from there I forwarded the event to the VScrollBar corresponding event, but still the VScrollBar events in never invoked. What should I do so...
0
1102
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 vscrollbar to scroll them all synchronically. I have tried several other methods such as the wndProc override method. It didn't work, so I'm trying this alternative method.
1
1742
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, one appears on the left and the other appears on the right. But, even without the screen shot, referring to the two cases as the "left case" and the "right case" seems to make as much sense as any other way of distinguishing the two cases. So...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.