The ArgumentException is happening because of this line.
Up vote 0 down vote favorite share g+ share fb share tw.
I have a problem to add pivot item in pivot control ..i want to add pivot item in pivot(Mycontrol) when I add next button . Code for next button static int selectitem; private void nextbuttonOnclick(object sender, RoutedEventArgs e) { if (selectitem! = list.Count() - 1) select(selectitem + 1); else { select(0); } } now it call the select method to add pivot item to pivot void select(int i) { MyControl.Items.Clear(); pivotItem = new PivotItem(); Grid sta = new Grid(); WebBrowser wb = new WebBrowser(); sta.
Background = new SolidColorBrush(Colors. White); var address = "" + list. ElementAt(i).
Header + "" + "" + "" + "" + list. ElementAt(i).Detail.ToString(); var ByteData = Encoding. UTF8.
GetBytes(address); System.Text. Encoding enc = System.Text.Encoding. UTF8; string myString = enc.
GetString(ByteData, 0, ByteData. Length); try { wb. Loaded += (sendr, ev) => { wb.
NavigateToString(myString); }; } catch (Exception ex) { } wb. Margin = new Thickness(0, 0, 0, 0); sta.Children. Add(wb); pivotItem.
Content = sta; MyControl.Items. Add(pivotItem); try { if (i == -1) MyControl. SelectedIndex = 0; else { selectitem = i; MyControl.
SelectedIndex = i; } } catch (IndexOutOfRangeException v) { } } but after adding one it shows a exception ie ArgumentException was unhandled ...thanx in advance windows-phone-7 link|improve this question asked Sep 5 '11 at 13:07Sandy317 12% accept rate.
The ArgumentException is happening because of this line: MyControl.Items.Clear(); That line removes all the items in the pivot control, but your internal selectitem variable doesn't account for that. In your code, there will always be only one pivot item (which sort of defeats the purpose of the pivot control). When you go to add item #2, the selectitem variable is set to 1 and the line MyControl.
SelectedIndex = 1; cases the exception since there is only 1 pivot item (0 based arrays, and all that stuff). Try removing the line that clears the pivot items above and see if it works for you. Otherwise, you're going to have to change the MyControl.
SelectedIndex = i; line to be MyControl. SelectedIndex = 0;. Just FYI - when I ran your sample, I needed to initialize selecitem to -1, not 0, or I got the same error message.
I also added code to set the PivotItem. Header property to something so it was easier to flip between pivot items. Just out of curiosity, why are you not doing this through DataBinding instead of all this code to load up items manually?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.