0
votes

I'm using the GridView control in WP7 to show records from isolated storage. I'm displaying these records at page load event of the page. The GridViewPage has 4 columns originally but when I come back to GridViewPage visiting other page the gridview showing duplicate columns( 8 columns this time).

Next time again I come back to GridViewPage it is showing 12 columns, but I don't see any changes in the corresponding XAML page.

But one thing before assigning value to ItemSource of the gridView I'm storing records from the isostore into one IList varialbe making some changes and assigning that IList variable to ItemSource of GridView.

private void GridViewPage_load(object sender, RoutedEventArgs r) { System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer(); dt.Interval = new TimeSpan(0, 0, 0, 1,0); // 1 seconds dt.Tick += new EventHandler(dt_Tick); dt.Start(); }

void dt_Tick(object sender, EventArgs e) { IList rawList = DBHelperMeeting.GetData(); int count = rawList.Count; for (int i = 0; i < count; i++) { /* in following lines i've written logic to get date and start_time from table records stored in IList variable-rawList and forming a DateTime variable */ string endDate =Convert.ToDateTime(rawList.ElementAt(i).Date.ToString()).ToShortDateString(); endDate += " "+rawList.ElementAt(i).End_Time;

            string startDate = Convert.ToDateTime(rawList.ElementAt(i).Date.ToString()).ToShortDateString();
            startDate+=" "+rawList.ElementAt(i).Start_Time;


            if ((bool)rawList.ElementAt(i).Flag == true)
            {
                TimeSpan st = Convert.ToDateTime(startDate) - DateTime.Now;
                //MessageBox.Show(st.ToString());
                TimeSpan et = Convert.ToDateTime(endDate) - DateTime.Now;
                //MessageBox.Show(et.ToString());
                if (st.Seconds < 0)
                {
                    if (et.Seconds < 0)
                    {
                        rawList.ElementAt(i).Flag = false;
                        rawList.ElementAt(i).Rem_Time = "Meeting Finished";
                    }
                    else
                    {
                        rawList.ElementAt(i).Rem_Time = "Meeting Started";
                    }
                }
                else if (st.Minutes > 0 && ((st.Hours * 60) + (st.Minutes)) < 16)
                {
                    rawList.ElementAt(i).Rem_Time = st.Minutes.ToString() + " Min.";
                }

            }
        }
        GridView1.ItemsSource = rawList;
      }

Actually i want to update the Rem_Time field of each record( i.e. meeting) according to time ( Rem_Time shows the remaining time for meeting)

1
Show your code, don't describe it. It will help us point out how you're adding 4 more columns to your grid each time the page is loaded, regardless of how many it already has.Matt Lacey

1 Answers

0
votes

Loaded event is raised all the time when all page components are loaded, even when you come back from another page. You need to load elements in constructor, for example.