for each loop - add item to listbox
-
Hi I was talking about somethign similar on the 2nd page but thought better to start a new post in case no one looked on the 2nd page :) Basically i have a for loop and in it I need to add items to a listbox I have the following but I am getting an error message: foreach (DataRow row in dataSetactorder.Tables[0].Rows) { listboxact.Items.Add (row[0]); } error: " The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments " any help would be great cheers :)
-
Hi I was talking about somethign similar on the 2nd page but thought better to start a new post in case no one looked on the 2nd page :) Basically i have a for loop and in it I need to add items to a listbox I have the following but I am getting an error message: foreach (DataRow row in dataSetactorder.Tables[0].Rows) { listboxact.Items.Add (row[0]); } error: " The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments " any help would be great cheers :)
.netman wrote:
The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments
The error message clear enough. It requires a string type, but you are supplying
DataRow
. It could be something likeforeach (DataRow row in dataSetactorder.Tables[0].Rows)
{
listboxact.Items.Add (row[0].ToString());
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
modified on Wednesday, April 9, 2008 4:54 AM
-
.netman wrote:
The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments
The error message clear enough. It requires a string type, but you are supplying
DataRow
. It could be something likeforeach (DataRow row in dataSetactorder.Tables[0].Rows)
{
listboxact.Items.Add (row[0].ToString());
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
modified on Wednesday, April 9, 2008 4:54 AM
ok ive filled up the listbox and now I want to check if any of the values in the listbox match a value from a text box WHat is the best way to do this ive got the following - stallactorder being the string result from the listbox and updateact the string value from the textbox How can i assign the values from a listbox to a string, or is there a better way to do it? pesudo code would be if listbox contains a value which matches textbox { } actual code so far if (stallactorder.Trim().Contains(updateact)) any help would be great cheers! :)
-
ok ive filled up the listbox and now I want to check if any of the values in the listbox match a value from a text box WHat is the best way to do this ive got the following - stallactorder being the string result from the listbox and updateact the string value from the textbox How can i assign the values from a listbox to a string, or is there a better way to do it? pesudo code would be if listbox contains a value which matches textbox { } actual code so far if (stallactorder.Trim().Contains(updateact)) any help would be great cheers! :)
I think you are following to my reply for your last post yesterday. In that I haven't meant to use a list box. I was suggesting to use
List<string>
class. It has aContains()
method and you can take the string easily from it.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
ok ive filled up the listbox and now I want to check if any of the values in the listbox match a value from a text box WHat is the best way to do this ive got the following - stallactorder being the string result from the listbox and updateact the string value from the textbox How can i assign the values from a listbox to a string, or is there a better way to do it? pesudo code would be if listbox contains a value which matches textbox { } actual code so far if (stallactorder.Trim().Contains(updateact)) any help would be great cheers! :)
-
Hi!! try the below code for (int i = 0; i <= ListBox1.Items.Count - 1; i++) { if (ListBox1.Items[i].ToString() == TextBox1.Text) { //your statement } }
-
Hi I was talking about somethign similar on the 2nd page but thought better to start a new post in case no one looked on the 2nd page :) Basically i have a for loop and in it I need to add items to a listbox I have the following but I am getting an error message: foreach (DataRow row in dataSetactorder.Tables[0].Rows) { listboxact.Items.Add (row[0]); } error: " The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments " any help would be great cheers :)
Why are you not just databinding to the table?