Retrieve Listbox items
-
Hello, Using C# on a web form with a textbox for the user to enter a word and then click on a button to have the word entered into a listbox. After the user has entered as many words as they wish they can then click on another button to have all of the words in the listbox processed. My question is: how do I retreive the words from the listbox? I would think I could loop through the listbox and get each word but I am not finding anything like this in my searches. For (int i = 0; i < Listbox1.Count; i = i+1) { wordlist[i] = Listbox1.?????; //processing code here } Can someone aim me in the right direction? Regards, Bill Antonacchio
-
Hello, Using C# on a web form with a textbox for the user to enter a word and then click on a button to have the word entered into a listbox. After the user has entered as many words as they wish they can then click on another button to have all of the words in the listbox processed. My question is: how do I retreive the words from the listbox? I would think I could loop through the listbox and get each word but I am not finding anything like this in my searches. For (int i = 0; i < Listbox1.Count; i = i+1) { wordlist[i] = Listbox1.?????; //processing code here } Can someone aim me in the right direction? Regards, Bill Antonacchio
for(int i=0; i<listBox1.Items.Count; i++)
{
wordlist[i] = listBox1.Items[i];
// processing code here
}#include "witty_sig.h"
-
for(int i=0; i<listBox1.Items.Count; i++)
{
wordlist[i] = listBox1.Items[i];
// processing code here
}#include "witty_sig.h"
Thank you, I guess. When I try to use this code there are several things that come up in the Build Error list in VS.NET. Doesn't there need to be a condition and an iteratr in the For statement. Also, Property or indexer 'string.this[int]' cannot be assigned to -- it is read only AND Cannot implicitly convert type 'System.Web.UI.WebControls.ListItem' to 'char' appear in the Build Error list. Can you give me a little more detail? This help is very much appreciated.
-
Thank you, I guess. When I try to use this code there are several things that come up in the Build Error list in VS.NET. Doesn't there need to be a condition and an iteratr in the For statement. Also, Property or indexer 'string.this[int]' cannot be assigned to -- it is read only AND Cannot implicitly convert type 'System.Web.UI.WebControls.ListItem' to 'char' appear in the Build Error list. Can you give me a little more detail? This help is very much appreciated.
I think you want ListBox1.Items[i].Text
-
I think you want ListBox1.Items[i].Text