This is a migrated thread and some comments may be shown as answers.

EnableRowVirtualization not working

5 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rocio
Top achievements
Rank 1
Rocio asked on 17 Sep 2012, 10:00 AM
Hello! I have a GridView in wich the EnableRowVirtualization is selected, I have read this means that the only rows generated are those that are visible. this is how I try to get the visible rows:
var rows = this.gridAlarm.ChildrenOfType<GridViewRow>();
 
            foreach (var row in rows)
            {
                if (row is GridViewNewRow)
                    continue;
 
                if (row.IsVisible)
                    logger.Debug("It's a visible row");
                var cell = row.Cells[7];
                TextBlock tx = (TextBlock)cell.Content;
                String content  = tx.Text;              
            }

My grid only has 7 rows, but it's small so at first it only shows 4 rows, but when I execute that code in "rows" I have all rows, not only the visible ones, and when I iterate thorough "rows", and row.IsVisible is allways true, for the 7 rows, no matter that only 3 rows are printed (you have to scroll down to see the others.

How can I recover only those rows that are visible actually in the grid?
Thanks a lot!

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Sep 2012, 10:18 AM
Hello,

 How many items you have in your collection bound to the grid?

Regards,
Vlad
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Rocio
Top achievements
Rank 1
answered on 17 Sep 2012, 10:28 AM
I have only seven, one item per row.
Thanks!
0
Vlad
Telerik team
answered on 17 Sep 2012, 10:44 AM
Hello,

 You should verify if the grid is not measured with infinity height. 

Greetings,
Vlad
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Rocio
Top achievements
Rank 1
answered on 17 Sep 2012, 11:08 AM
Hello, my grid had an Auto Height, so I changed it to 100

<telerik:RadGridView Margin="43,139,0,0" Name="gridAlarm" AutoGenerateColumns="False" ColumnWidth="Auto"        telerik:StyleManager.Theme="Vista" CanUserDeleteRows="False" CanUserInsertRows="False" ActionOnLostFocus="None"
                     Height="100" VerticalAlignment="Top" Visibility="Hidden" HorizontalAlignment="Left"
                                          Width="Auto" RowLoaded="gridAlarm_RowLoaded" CanUserSortColumns="False"
                    
ShowGroupPanel="False">
 
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn UniqueName="PtNum" Header="PtNum" DataMemberBinding="{Binding Key}" Width="auto"/>
                            <telerik:GridViewDataColumn Header="Timestamp" DataMemberBinding="{Binding Value.Timestamp}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Value.Description}"  Width="auto"/>
                            <telerik:GridViewDataColumn Header="Comment" DataMemberBinding="{Binding Value.Comment}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Point" DataMemberBinding="{Binding Value.Ptname}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="RTU" DataMemberBinding="{Binding Value.Rtu}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Category" DataMemberBinding="{Binding Value.Category}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Table" DataMemberBinding="{Binding Value.Dbname}"  Width="auto" />
                            <telerik:GridViewDataColumn Header="Field" DataMemberBinding="{Binding Value.Fldname}"  Width="auto" />
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>

and tried to execute it, with this height I can see three rows, but when I debug the code:

private void radButton1_Click(object sender, RoutedEventArgs e)
        {
            var rows = this.gridAlarm.ChildrenOfType<GridViewRow>();
  
            foreach(var row in rows)
            {
                if(row is GridViewNewRow)
                    continue;
  
                if(row.IsVisible)
                    logger.Debug("It's a visible row");
                var cell = row.Cells[7];
                TextBlock tx = (TextBlock)cell.Content;
                String content  = tx.Text;              
            }
        }
 
The "rows" collection has 4 columns, I attach two screen prints so you can see what I am talking about.
It gets rows from one to 4, when in the grid I can only see rows 1 to three.

does "rows" always get an extra row? if so, I could not treat the last row, but I am not sure that it's always the same.
Hope you can help me. Thanks!
0
Rocio
Top achievements
Rank 1
answered on 17 Sep 2012, 11:29 AM
Hello! I have been doing more tests, I have scrolled down to the button of the grid, and I see rows 6 and 7, and in the "rows" collection I get those two rows, not the extra one. I don't know how to solve his, because I can't just ignorate the last row, so that it's not always a no visible row.
Thanks!
Tags
GridView
Asked by
Rocio
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rocio
Top achievements
Rank 1
Share this question
or