简体   繁体   中英

Datagrid on demand load off

I have a SDK:DATAGRID with 20 columns or so, when it opens up it only shows four fields/columns. Which is what I want and how I designed it

Basically I'm grabbing information based on the user click - EXAMPLE:

OWNERNAME.Text = ((TextBlock)EPICGrid.Columns[1].GetCellContent(EPICGrid.SelectedItem)).Text;

and/or

OWNERNAME2.Text = ((TextBlock)EPICGrid.Columns[16].GetCellContent(EPICGrid.SelectedItem)).Text;

What I'm running into it doesn't grab the information in the cell unless if I scroll and show the column so I can only grab the first 4 columns of data because they show when the grid becomes visible.

I can't grab data from columns 5 -20 unless I scoll over and make those columns visible. They don't have to be visible during the click...it just seems like the data doesn't really load until I view the column.

I guess I should say the first record/row loads all the data/cells/columns and I can grab any data from the first record but the problem happens with records 2 - *.

Just to clarify - my issue is not a visibility of my columns or rows. My issue is the SDK DataGrid seems like it is loading the data on demand. So if the column is not in view at one point or another the information in the cell is not available.

I don't want to show all columns and I don't want to give the user the ability to see all columns so I want to disable the scroll bars but when a user clicks on a certain row I need to grab information in certain cells and since the column is not load yet the information is not there.

How do I turn the feature load on demand off?

I did a search and found out that someone had a similar problem with rows loading and the suggestion was setting the VirtualizingStackPanel.VirtualizationMode = Standard

It almost like the problem is stemmed from VirtualizingStackPanel.VirtualizationMode but I set this property to standard and recycle and no luck.

Here's definition:

By default, a VirtualizingStackPanel creates an item container for each visible item and discards it when it is no longer needed (such as when the item is scrolled out of view). When an ItemsControl contains a lot of items, the process of creating and discarding item containers can negatively affect performance. When VirtualizingStackPanel.VirtualizationMode is set to Recycling, the VirtualizingStackPanel reuses item containers instead of creating a new one each time.

On initial load, if the cell is not visible I can not grab the cells content (unless it is the first record/row). Once and after the cell / column is visible then the information is available.

I think you are expected to deal with the data that the row is bound to directly and not pull the data out of the controls. This makes sense since it is two way data binding so the data is updated as you are changing it (assuming it implements the INotifyPropertyChanged Interface).

An example would be where a datagrid is bound to a collection of type MyEntity.

     private void DataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.DataGrid1.SelectedItem == null)
                return;

            MyEntity myEntity = (MyEntity)this.DataGrid1.SelectedItem;

            // at this point you have the (updated) data the row is bound to.
           MessageBox.Show("You Selected: " + myEntity.name);
           ...

Another example is where there is a button on each row. The code to process when a button is clicked looks something like:

      private void btnProcessEntity_Click(object sender, RoutedEventArgs e)
      {

         Button btn = sender as Button;
         MyEntity myEntity = btn.DataContext as MyEntity;

          // clicking a button in a row doesn't select the row, so select it.
         this.DataGrid1.SelectedItem = myEntity;  
         MessageBox.Show("Will Process: " + myEntity.name);

          ...
       }

If you are not familiar with some of the technologies that normally are used with Silverlight check out these Video Tutorials . It is VB.Net, but the code is really not the focus - it is focused on a Silverlight application architecture. I would start with "Intro to SL4 and WCF Ria Services" and then view one of the ones on MVVM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM