Hi,
in my current application i have a button that shows a popup when clicked. this popup form contains an XamPivotGrid that takes its values from an xml.
Also in the popup there is a button that when clicked saves the information edited in the grid to the xml.
The first time i open the popup and click the button to save the values everything works fine and the popup closes. The second time i click to open the popup get this message: Object reference not set to an instance of an object.
and below is what is called when i open the popup:
ObservableCollection<MarketShares> mSharesData = SampleDataGenerator.GenerateMarketShares((DateTime)this.avgdatepicker1.Tag, (DateTime)this.avgdatepicker2.Tag, 2);
SampleFlatDataSourceAverageVsBrand flatDataSource = new SampleFlatDataSourceAverageVsBrand();
flatDataSource.Measures.CollectionChanged += Measures_CollectionChanged;
flatDataSource.ItemsSource = mSharesData;
this.AvgPivotGrid.DataSource = flatDataSource;
// this.AvgPivotGrid.DataSource.Measures.CollectionChanged += new NotifyCollectionChangedEventHandler(Measures_CollectionChanged);
this.AvgPivotGrid.CellControlAttached += new EventHandler<PivotCellControlAttachedEventArgs>(AvgPivotGrid_CellControlAttached);
this.AvgPivotGrid.CellEdited += AvgPivotGrid_CellEdited;
this.AvgPivotGrid.LayoutLoaded += AvgPivotGrid_LayoutLoaded;
Please advise,
Nazha
Hello,
Is there any additional information about where this exception occurs? Have you unsubscribed from the pivot grid events when the popup is closed?
this.AvgPivotGrid.CellControlAttached -= new EventHandler<PivotCellControlAttachedEventArgs>(AvgPivotGrid_CellControlAttached);this.AvgPivotGrid.CellEdited -= AvgPivotGrid_CellEdited;this.AvgPivotGrid.LayoutLoaded -= AvgPivotGrid_LayoutLoaded;
Plamen.
I tried what you suggested. it didn't work. this error is happening when i am calling:
in this function i am accessing the xml and getting the values: below queries (valuequery, manualquery) are returning null although MarketSharesDS.Descendants("marketsharevalue") has values. these work only the first time the popup is called. After i close it and open it again they return null.
public static ObservableCollection<MarketShares> GenerateMarketShares(DateTime start, DateTime end, int ntype)
{
ObservableCollection<MarketShares> mSharesCollection = new ObservableCollection<MarketShares>();
try
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
using (IsolatedStorageFileStream isoStreamread = new IsolatedStorageFileStream("exportmsharesdata.xml", FileMode.Open, isoStore))
XElement MarketSharesDS = XElement.Load(isoStreamread);
string cbrand;
int brandcount;
GetListofBrands brandslist = new GetListofBrands();
List<brandsObject> uniquebrands = brandslist.generatelist("8113", "4D7FDF9F-9175-4476-BD79-3D6A1FBBA8C3");
brandcount = brandslist.nbofbrands();
MainPage.maxbrandwidth = brandslist.maxbrandslength();
TestAvg.nbofbrands = brandcount;
DateTime curDate;
string curFormatDate;
library functions = new library();
double curvalue = -1;
double res;
bool manual;
for (int nbrands = 0; nbrands < brandcount; nbrands++)
MarketShares msharesobj = new MarketShares();
cbrand = uniquebrands.ElementAt(nbrands).brandref;
for (int mstype = 0; mstype < 2; mstype++)
curvalue = -1;
IEnumerable<double> valuequery;
IEnumerable<bool> manualquery;
// filtering the xml data to the brand specified
if (mstype == 0)
valuequery = (from el in MarketSharesDS.Descendants("marketsharevalue")
where (string)el.Element("brandref") == cbrand && (string)el.Element("yearval") != "-1" && (string)el.Element("msval") != "-1" && (functions.YearMonthToDate((string)el.Element("yearval")) >= (start)) && (functions.YearMonthToDate((string)el.Element("yearval")) <= (end))
select (functions.GetFilteredList(el)).msval);
manualquery = (from el in MarketSharesDS.Descendants("marketsharevalue")
where (string)el.Element("brandref") == cbrand && (string)el.Element("yearval") != "-1" && (string)el.Element("msval") != "-1" && (functions.YearMonthToDate((string)el.Element("yearval")) >= (start)) && (functions.YearMonthToDate((string)el.Element("yearval")) <= (end)) && (bool)el.Element("mvalmanual") == true
select (functions.GetFilteredList(el)).mvalmanual);
}
else
where (string)el.Element("brandref") == cbrand && (string)el.Element("yearval") != "-1" && (string)el.Element("msvol") != "-1" && (functions.YearMonthToDate((string)el.Element("yearval")) >= (start)) && (functions.YearMonthToDate((string)el.Element("yearval")) <= (end))
select (functions.GetFilteredList(el)).msvol);
where (string)el.Element("brandref") == cbrand && (string)el.Element("yearval") != "-1" && (string)el.Element("msval") != "-1" && (functions.YearMonthToDate((string)el.Element("yearval")) >= (start)) && (functions.YearMonthToDate((string)el.Element("yearval")) <= (end)) && (string)el.Element("mvolmanual") != "false"
select (functions.GetFilteredList(el)).mvolmanual);
if (valuequery.Count() != 0)
res = valuequery.Average();
res = -1;
if (manualquery.Count() != 0)
manual = true;
manual = false;
curvalue = Math.Round(res, 2);
msharesobj.msvalue = curvalue;
msharesobj.mvalmanual = manual;
msharesobj.msvolume = curvalue;
msharesobj.mvolmanual = manual;
} //end of looping of brands
msharesobj.Brands = GetBrandName(cbrand);
mSharesCollection.Add(msharesobj);
return mSharesCollection;
catch (Exception ex)
System.Windows.MessageBox.Show(ex.Message);