I have been trying to pass a string value from one method into another. Here are my two methods.
Method 1-
public void listBox1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var c_id = (e.AddedItems[0] as Foodlist).C_ID;
string listboxid = c_id.ToString();
}
}
I want the string listboxid value in my second method so that I can use it for comparison.
Method 2-
public void deletemyfood()
{
using (FoodDataContext context = new FoodDataContext(Con_String))
{
string listboxindex = listboxid;
IQueryable<FoodViewModel> foodQuery = from c in context.FoodTable where c.C_ID.ToString() == listboxindex select c;
....
}
}
any ideas or suggestions?
Here’s a Simple example on how you can use return values and parameters:
In this example, the method
Method1takes a string parameter and then returns a string.In your case you might want to change the method signature of
DeleteMyFoodto this:public void DeleteMyFood(string foodId)If you want some sort of result though, too know when the method succeeded or not, you might want to have a value returned from the method as well. This can be done by modifying the method signature once again:
public bool DeleteMyFood(string foodId)If I understand correctly based on your comments, you want to change the event handler to this:
This requires that the method
DeleteMyFoodaccepts a parameter of type string, so we need to change that as well: