473,407 Members | 2,629 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,407 software developers and data experts.

Problem with listbox horizontal scrollbar

Hello all

I have a fairly simple listbox into which I add, insert, and remove strings

It has the following property settings
HorizontalScrollbar - true
HorizontalExtent -
ScrollAlwaysVisible - Fals

The problem I am having is that the horizontal scrollbar range doesn't work right. If I add a string, the first time the sting width exceeds the control width the bar appears, but it's off by a few pixels so the last character is truncated. If I add longer items, it doesn't update so I can't see the end of them. If I insert items, it never updates. Delete only seems to work if the entire horizontal scrollbar should disappear

I ended up writing code (at end of this post) which goes through all the strings and uses the Graphics.MeasureString method, then sets HorizontalExtent to the maximum result. It works, but seems very cumbersome - and I can't find an event which fires when the Items-collection changes which could simply call this method. Instead, I need to go through my code and add calls to this at any point the collection might change

Is this a known issue with listboxes or am I doing something dumb. I can't believe proper scrollbar operation requires added code

Any tips appreciated
Marku

Here is the code I had to add

private void UpdateHorzScroll()

Graphics g=Graphics.FromHwnd(Handle)
int wid=0
foreach (object obj in MyListBox.Items)

int swid=(int)(g.MeasureString(obj as string,Font).Width)
if (swid > wid) wid=swid

MyListBox.HorizontalExtent=wid
Jul 21 '05 #1
0 1680

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

Similar topics

0
by: Lundy | last post by:
greetings, The listbox control on my aspx page has a vertical scrollbar. But some of the text extends beyond the right limit of the listbox. I don't see a horizontal scrollbar, and I don't...
0
by: markusszil | last post by:
Hello all I have a fairly simple listbox into which I add, insert, and remove strings It has the following property settings HorizontalScrollbar - true HorizontalExtent - ScrollAlwaysVisible...
0
by: Mr. Beck | last post by:
I have a simple application that has a listbox for displaying text in it. The functionality of it is to color particular parts of the text that is displayed from a file. I have used similar coding...
0
by: rn5a | last post by:
How do I make a ListBox display the horizontal scrollbar if the text of any of the items in the ListBox exceeds the width of the ListBox? Unlike the vertical scrollbar which gets displayed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.