|
-
Aug 17th, 2009, 03:02 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Yet Another ListView Question
Hiya People,
Newbie here, I've been trawling these forums, and the net all day. Modified lots of code examples to try and fit my needs. Nothing as yet, have I managed to get to work
I have finally decided to post my own question, so here goes.
I have a CheckedListView (suggested in a post I read, and it seems to fit my needs) which I populate with the filtered names of the files from within a selected folder.
Then the user selects the ones to process, by using the checkboxes. So basically it is a single column text box with checkboxes down the left hand side.
What I've been trying to do is get the selected text (i.e. the name of the file) and put it in a string array for later use.
Please make any answers verbose, as I've not been using .net for very long, and need a bit of spoon feeding.
I've used various forms of: For each item as .....ListViewItem......Next and also various forms of for x = 1 to Listitem.count......Next
e.g.
Code:
Dim DWGListArray() As String
Dim X As Integer = LSCheckedListBox1.Items.Count
Dim Ctr As Integer
For Ctr = 0 To X
If LSCheckedListBox1.Items(Ctr).Checked Then
DWGListArray(Ctr) = LSCheckedListBox1.Items(Ctr).Text
Debug.Print(DWGListArray(Ctr))
End If
Which would you suggest, ensuring that the filename text goes into the str array. Any help would be very much appreciated.
Regards
GB
-
Aug 17th, 2009, 03:14 PM
#2
Re: Yet Another ListView Question
Well, why don't you tell us what isn't working?
Two things though:
- Instead of looping from 0 to X you should loop from 0 to X-1, since the items are zero-based. If you have 3 items (X = 3) then items(2) is the last item, and items(3) does not exist.
- Instead of using an array, I advice you to use a List(Of String) instead. Replace the first line with "Dim DWGList As New List(Of String)" and replace the 'add to array' code with "DWGList.Add(name here...)".
-
Aug 17th, 2009, 03:22 PM
#3
Re: Yet Another ListView Question
The checkedlistbox class has the CheckedIndices and CheckedItems properties. If you need to get the text of the checked items then you just read the checkeditems property, which returns a checkeditemcollection that you can loop thru and get the individual checked item
Code:
For Each checkedItem As Object In LSCheckedListBox1.CheckedItems
Debug.WriteLine(checkedItem.ToString)
Next
There is no need to create a separate array to hold these checked items because you can access them any time via the checkedlistbox.checkeditems property.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Aug 17th, 2009, 03:25 PM
#4
Fanatic Member
Re: Yet Another ListView Question
vb Code:
For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1 test &= CheckedListBox1.CheckedItems(i).ToString Next
replace the test &= with whatever variable you're using to store the string.
(*edit* or you can go the route above )
Last edited by BackWoodsCoder; Aug 17th, 2009 at 03:26 PM.
Reason: too slow!
-
Aug 17th, 2009, 03:46 PM
#5
Thread Starter
Addicted Member
Re: Yet Another ListView Question
Gee, Thank a bunch people, That's really great, that'll give me something to get on with tomorrow. I was getting really disheartened with my lack of progress today, and hopefully I'll get this sorted tomorrow.
@ NickThissen - I couldn't post too much as I mucked about with so much code today, its difficult to know which bit was closest to being right, and which was a total pile of *^*&(
-
Aug 18th, 2009, 01:52 AM
#6
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|