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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable items in a filelistbox ? 1

Status
Not open for further replies.

philmck

Programmer
Feb 19, 2004
8
GB
I have a filelistbox from which the user can select files and add/remove them to another 'target' listbox.

Is there a way of disabling individual items in the filelistbox once they are added to the listbox?

 
I knocked up some code to do listbox move from source to target. You need to midify it so that:

The source listview needs to be populated with the files in the folder

change the code it doesn't remove from the source but sets the listitem in arrFrom to disabled when the move is done.

If you need more i will write the code for you.

below is my source:

Dim o As Access.Application
Dim blnUserOpened As Boolean
Private Sub Command1_Click()
blnUserOpened = True
Set o = New Access.Application
o_OpenCurrentDatabase "C:\Program Files\Altova\XMLSPY2004\Examples\Tutorial\company.mdb"
o.Visible = True
Timer1.Interval = 200
End Sub

Private Sub Timer1_Timer()
On Error GoTo errh
If blnUserOpened Then
DoEvents
'test if user closed, if so this will cause error 2467
If LenB(o.CurrentProject.Name) > 0 Then Exit Sub

End If
exith:

Exit Sub
errh:
If Err.Number = 2467 Then
Set o = Nothing
Timer1.Interval = 0
End If
Resume exith
End Sub

 
I'm so sorry mate, I just pasted wrong code into the last thread!

here is the right code:

Option Explicit
Option Compare Binary



Private Function MoveSelectedToListView(ByVal lvwSource As ComctlLib.ListView, _
ByVal lvwTarget As ComctlLib.ListView, _
Optional ByVal RemoveSource As Boolean = True)
Dim li As ListItem
Dim i As Integer
Dim iTo As Integer
Dim iFrom As Integer
Dim arrFrom() As String
Dim arrTo() As String
Dim bItemsToMove As Boolean

For Each li In lvwSource.ListItems

If li.Selected Then
'set my flag
bItemsToMove = True
'get all selected items into one array
ReDim Preserve arrTo(iTo + 1)
arrTo(iTo) = li.Text
iTo = iTo + 1

Else
'get all unselected into another array
ReDim Preserve arrFrom(iFrom + 1)
arrFrom(iFrom) = li.Text
iFrom = iFrom + 1
End If

Next li

'now clear the source list and put the unselected items back
If bItemsToMove Then
If RemoveSource = True Then
lvwSource.ListItems.Clear
For i = 0 To UBound(arrFrom) - 1
lvwSource.ListItems.Add , , arrFrom(i)
Next i
End If
'now populate the target listbox - don't clear because items may exist already

For i = 0 To UBound(arrTo) - 1
lvwTarget.ListItems.Add , , arrTo(i)
Next i
End If

Set li = Nothing
End Function

Private Sub Command1_Click()
MoveSelectedToListView ListView1, ListView2, True
End Sub

Private Sub Form_Load()
Dim i
For i = 1 To 10
ListView1.ListItems.Add , , "item" & CStr(i)
Next i
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top