Dear,
I'm trying to add a whole bunch of data to the WebDataMenu. The data is up to 5 levels deep and each level can have a lot of data. But, somehow the webdataMenu does not accept it when I add items to items. I can add as many items to an item, it only remembers the last one. Below you'll find a part of my code, can you please advice how to add all my data to the menu
private void SetupMenuTreeDiscovery()
{ XlInterface l_InterfaceMeal = new XlInterface("WWW.Meal"); XlMessage l_GetMealType = l_InterfaceMeal.Message("GetMealType"); DataMenuItem l_MenuItem; //Set the attributes for GetMealType l_GetMealType.Attribute("SiteId").Value = m_SiteId; l_GetMealType.Attribute("MealId").Value = m_MealId; //Send the request if (l_GetMealType.Send()) { //Walk through the ingredient groups foreach (XlClass l_IngredientGroup in l_GetMealType.List("IngredientGroups").Items) { l_MenuItem = new DataMenuItem(); l_MenuItem.Text = l_IngredientGroup.Attribute("MealTypeIngredientGroupName").Value; l_MenuItem.Value = l_IngredientGroup.Attribute("IngredientGroupId").Value; //Get the ingredients for this category AddIngredientGroupsToDiscoveryTree(l_MenuItem, l_IngredientGroup.Attribute("IngredientGroupId").Value); //Add the main category to the menu menu_Discovery.Items.Add(l_MenuItem); } } } private void AddIngredientGroupsToDiscoveryTree(DataMenuItem p_MenuItem, string p_IngredientGroupId) { XlInterface l_InterfaceMeal = new XlInterface("WWW.Meal"); XlMessage l_GetIngredientGroup = l_InterfaceMeal.Message("GetIngredientGroup"); DataMenuItem l_MenuItem; //Set the attributes l_GetIngredientGroup.Attribute("SiteId").Value = m_SiteId; l_GetIngredientGroup.Attribute("IngredientGroupId").Value = p_IngredientGroupId; //Send the request if (l_GetIngredientGroup.Send()) { //Add ingredient groups foreach (XlClass l_IngredientGroup in l_GetIngredientGroup.List("IngredientGroups").Items) { l_MenuItem = new DataMenuItem(); l_MenuItem.Text = l_IngredientGroup.Attribute("IngredientGroupName").Value; l_MenuItem.Value = l_IngredientGroup.Attribute("IngredientGroupId").Value; p_MenuItem.Items.Add(l_MenuItem); //Add the ingredients to this category AddIngredientGroupsToDiscoveryTree(l_MenuItem,l_IngredientGroup.Attribute("IngredientGroupId").Value); } } }
Hello,
From what I see is that you have to switch the order of following lines:
//Get the ingredients for this categoryAddIngredientGroupsToDiscoveryTree(l_MenuItem, l_IngredientGroup.Attribute("IngredientGroupId").Value);
//Add the main category to the menumenu_Discovery.Items.Add(l_MenuItem);
You have to first add the empty item to its collection, and then populate it.