Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > question about list boxes


Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2006, 03:41 PM
ophelius ophelius is offline
Newcomer
 
Join Date: Oct 2006
Posts: 11
Default question about list boxes


Is there a way to add items in list boxes that are not clickable? I need catagorie seperators which aren't part of the list options.

Example:

--Section 1-- <-can't click this
Item1
Item2
Item3
--Section 2-- <-can't click this
Item1
Item2
--Section 3-- <-can't click this
Item1
Item2
Reply With Quote
  #2  
Old 10-06-2006, 03:44 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

Sounds more like a situation for a Treeview.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #3  
Old 10-06-2006, 03:50 PM
ophelius ophelius is offline
Newcomer
 
Join Date: Oct 2006
Posts: 11
Default

Thanks. I'll look into it. I'm very new to VB
Reply With Quote
  #4  
Old 10-06-2006, 05:43 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
Default

Well, , a bit cheesy perhaps, but you could save the listindex as you go, and check the selection and if it contains something to identify is as unselectable, set the index back to what it was before.

Of course, if they use the arrow key to scroll up or down, this code will prevent you from scrolling out of a section. You could probably add other code to get around that situation. One option, rather than set the index back to what it was, if the old index was less than the current index, you're moving down the list so set the listIndex to ListIndex + 1.
Set to ListIndex - 1 if moving up the list.

Code:
Option Explicit Dim LastIndex As Long Private Sub Form_Load() Dim i As Integer, j As Integer 'Load up some test conditions For i = 1 To 3 List1.AddItem "--Section " & CStr(i) & " --" For j = 1 To 5 List1.AddItem "Item" & CStr(j) Next Next End Sub Private Sub List1_Click() If Left$(List1.Text, 2) = "--" Then List1.ListIndex = LastIndex Else LastIndex = List1.ListIndex End If End Sub


Edit: The skip up/down version.
Code:
Private Sub List1_Click() If Left$(List1.Text, 2) = "--" Then If LastIndex < List1.ListIndex Then List1.ListIndex = List1.ListIndex + 1 Else List1.ListIndex = List1.ListIndex - 1 End If End If LastIndex = List1.ListIndex End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 10-06-2006 at 05:50 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->