Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect if scrollbar is visible on multicolumn listbox 1

Status
Not open for further replies.

waytech2003

Programmer
Jul 14, 2003
316
US
I have a listbox on a form and have the multicolumn set to true. I would like to know if and when the horizontal scrollbar becomes visible when I am adding items to it in code. I can not seem to find an answer to this. Seems to me that there would be property, ScrollbarVisible, to test.

Code:
Dim mLastNumber As Integer = 10000
Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
   mLastNumber = mLastNumber + 1
   ListOfNumbers.Items.Add(mLastNumber.ToString)
End Sub
 

You can do this with the ListBox's ClientRectangle property. Before you add an item to the Listbox, get its ClientRectange and make note of the Height property. As you add items, get the ClientRectangle again and check its Height property again. When the Height property becomes less than the original value, then the horizontal scroll bar is showing. Here's some code to test, just use a narrow ListBox so the scrollbars will show up:

Dim c As Rectangle

c = ListBox1.ClientRectangle

MsgBox(c.Height)

ListBox1.Items.Add("xxxxxxxxxxxxxxxxxxxxxxxxx")

c = ListBox1.ClientRectangle

MsgBox(c.Height)

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top