Welcome to the Xceed Community | Help
Community Search  
More Search Options

Select a specific Row after Refreshing my ItemSource

Sort Posts: Previous Next
  •  05-09-2010, 9:26 PM Post no. 26772

    Select a specific Row after Refreshing my ItemSource

    I am using a DataGridControl with the ItemSource bound to a DataGridCollectionViewSource.  When I change the DataGridCollectionViewSource.ItemsSource I would like to reselect a specific Row if it still resides in the Grid.

    My code looks like this:

      // Rerun last query to get changes
      ReRunLastQuery();
      ipIssueGrid.Items.Refresh();

      // Get Grid to rebind
      DataGridCollectionView viewSource = (DataGridCollectionView)ipIssueGrid.ItemsSource;
      viewSource.Refresh();
      ipIssueGrid.Items.Refresh();

      // Select Added Issue
      foreach (IpIssueQuery ipQuery in ipIssueGrid.Items)
      {
          if (ipQuery.IpIssue.IpIssueId == ipIssueToAdd.IpIssueId)
          {
              ipIssueGrid.CurrentItem = ipQuery;
              ipIssueGrid.SelectedItem = ipQuery;
              break;
          }
      }

    I see that the DataGridCollectionViewSource has seen my OnPropertyChanged() event for the ItemSource and has called my Get Property before I set my CurrentItem and SelectedItem but it looks like the Grid hasn't really rebuilt it's ItemSource and I end up with the 1st row in the grid always selected.

     Any suggestions?

  •  06-22-2010, 4:32 AM Post no. 27220 in reply to 26772

    Re: Select a specific Row after Refreshing my ItemSource

    I have a similar issue. I have tried iterating through the grid items using Dispatcher with a low priority but I can't get that to work as the rows are always null because the grid is probably still updating or whatever. I have come to the conclusion that you can't adequately set a CurrentItem in the grid and have thus swapped the grid out and redesigned the GUI to not use a grid. Annoying, as I have wasted a lot of time trying to do something which a grid should be able to do but I feel a lot happier now I have abandoned using a grid.

     

  •  06-22-2010, 9:40 AM Post no. 27223 in reply to 26772

    Re: Select a specific Row after Refreshing my ItemSource

    Calling dataGrid.UpdateLayout(); will force the rows to load so that it's ready for you do the row selection, but it slows down the load time tremendously (by about 300% for me).

     

    For me, I was trying to auto fit the width of all columns as soon as a new dataset was assigned to the grid, but I found that increase in loading time was not worth the feature, so I dropped the idea of doing any sort of work on the grid when it is first loaded with data.


    Alain
  •  06-22-2010, 9:53 AM Post no. 27225 in reply to 27223

    Re: Select a specific Row after Refreshing my ItemSource

    Hi Alain, thanks for the suggestion, I tried it and it didn't work. I think setting the selected item is a non starter.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.