Click here to Skip to main content
15,914,820 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Cannot find ContextMenu control in vb.net Pin
cyberexel4-Aug-10 8:05
cyberexel4-Aug-10 8:05 
GeneralRe: Cannot find ContextMenu control in vb.net Pin
Andraw Tang4-Aug-10 10:25
Andraw Tang4-Aug-10 10:25 
GeneralRe: Cannot find ContextMenu control in vb.net Pin
cyberexel4-Aug-10 23:11
cyberexel4-Aug-10 23:11 
QuestionGet Primary Field and Foreign Fields from Access Table Pin
cyberexel4-Aug-10 4:49
cyberexel4-Aug-10 4:49 
AnswerRe: Get Primary Field and Foreign Fields from Access Table Pin
cyberexel5-Aug-10 6:39
cyberexel5-Aug-10 6:39 
QuestionRemote TCP file Transferring Pin
rezafathi3-Aug-10 14:15
rezafathi3-Aug-10 14:15 
AnswerRe: Remote TCP file Transferring Pin
Garth J Lancaster3-Aug-10 17:25
professionalGarth J Lancaster3-Aug-10 17:25 
Question[VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom3-Aug-10 9:43
The Mighty Atom3-Aug-10 9:43 
Imaging the following:

You have a ListView with some items in it. Using the Control key, you select some items. Then you click a button which iterates through all the items to save them in a text file so they can be retrieved later. However, you also want to remember the items that were selected. This is very simple to do, you just create a ListViewItem object and then you use the Selected propery to check which items are selected and which are not, like so:

For Each Item As ListViewItem In ListView1.Items
    If Item.Selected Then
        MessageBox.Show(Item.Text & "|" & True & vbCrLf)
    Else
        MessageBox.Show(Item.Text & "|" & False & vbCrLf)
    End If
Next


Then, using a streamreader, i read each line and use the split method to split the line (That's where the | character comes in, its the delimiter) and put both halfs of the line in an array. The first index of the array contains the item text, the second index either True or False. Using an If statement, i check wether the second array index is true or false. Is it true, then select the item. Is it False, don't select it.

All the above works fine and actually is not the problem. The problem is that i need this to work on a ListBox instead rather than a ListView. This is where i get stuck because the ListViewItem datatype does'nt work on ListView items and thus the Selected property is unavailable. I tried using the more generic Object datatype like so:

For Each Item As Object In ListBox1.Items
    If Item.Selected Then
        MessageBox.Show(Item.Text & "|" & True & vbCrLf)
    Else
        MessageBox.Show(Item.Text & "|" & False & vbCrLf)
    End If
Next


Though the designer does'nt give any errors, but as soon as i press the button, i get this error:

Het openbare lid Selected voor type String is niet gevonden.

For some reason, the error text is in Dutch but basically it says that 'Selected' is not found for the String datatype, which makes sense because listbox items are of type string.

So the baseline question here is:

How do i check which items are selected and which are not without replacing the listbox with a listview?

I hope it makes sense to you.
Thanks.
http://www.themightyatom.nl

AnswerRe: [VB10] Check which ListBox items are selected and which are not Pin
Eddy Vluggen3-Aug-10 10:51
professionalEddy Vluggen3-Aug-10 10:51 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom3-Aug-10 11:53
The Mighty Atom3-Aug-10 11:53 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
Luc Pattyn3-Aug-10 12:31
sitebuilderLuc Pattyn3-Aug-10 12:31 
GeneralRe: [VB10] Check which ListBox items are selected and which are not [modified] Pin
The Mighty Atom3-Aug-10 13:01
The Mighty Atom3-Aug-10 13:01 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom4-Aug-10 7:14
The Mighty Atom4-Aug-10 7:14 
AnswerRe: [VB10] Check which ListBox items are selected and which are not Pin
Luc Pattyn4-Aug-10 8:12
sitebuilderLuc Pattyn4-Aug-10 8:12 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom4-Aug-10 8:46
The Mighty Atom4-Aug-10 8:46 
AnswerRe: [VB10] Check which ListBox items are selected and which are not Pin
Luc Pattyn4-Aug-10 9:25
sitebuilderLuc Pattyn4-Aug-10 9:25 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom4-Aug-10 9:45
The Mighty Atom4-Aug-10 9:45 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
Luc Pattyn4-Aug-10 11:42
sitebuilderLuc Pattyn4-Aug-10 11:42 
QuestionInput data set changed dynamically according to option selection in VB.net 2005 Pin
Andraw Tang2-Aug-10 12:03
Andraw Tang2-Aug-10 12:03 
AnswerRe: Input data set changed dynamically according to option selection in VB.net 2005 Pin
Eddy Vluggen3-Aug-10 10:55
professionalEddy Vluggen3-Aug-10 10:55 
GeneralRe: Input data set changed dynamically according to option selection in VB.net 2005 Pin
Andraw Tang4-Aug-10 3:49
Andraw Tang4-Aug-10 3:49 
GeneralRe: Input data set changed dynamically according to option selection in VB.net 2005 Pin
Eddy Vluggen4-Aug-10 4:21
professionalEddy Vluggen4-Aug-10 4:21 
GeneralRe: Input data set changed dynamically according to option selection in VB.net 2005 Pin
Andraw Tang4-Aug-10 4:39
Andraw Tang4-Aug-10 4:39 
Questiondata access sample project Pin
soulrebelpd2-Aug-10 11:05
soulrebelpd2-Aug-10 11:05 
AnswerRe: data access sample project Pin
Yusuf2-Aug-10 12:48
Yusuf2-Aug-10 12:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.