Http://kinbor.cnblogs.com/archive/2005/11/04/269152.html
After reading the question raised by kinbor on the above page, I found it interesting, but there is no texture, so I moved it here, although I do not advocate using the method of assigning values to the DataGrid in this set-value application (I think it is better to change the data source as he said, because the DataGrid is exposed, there are too many uncertainties), but this issue is worth exploring.
In addition Article In addition to the content added in the comments, I added a section in the DataGrid scroll event. Code To output the current row. Private Void Dginfo_scroll ( Object Sender, system. eventargs E)
{
Strmessage+ ="Scroll, row: \ t" +Dginfo. currentcell. rownumber. tostring ()+ "\ N";
}
Private Void Tbinfo_leave ( Object Sender, system. eventargs E)
{
Classtest clstest = New Classtest ();
// Dginfo. Enabled = false;
For (; Clstest. itempvalue < 15 ; Clstest. Improve ())
{
Strmessage + = " Loop, before: " + Clstest. itempvalue. tostring () + " \ N " ;
Dginfo [clstest. itempvalue, 4 ] = Clstest. itempvalue. tostring () + " - " + Tbinfo. text;
Dginfo. Refresh ();
Strmessage + = " Loop, after: \ t " + Clstest. itempvalue. tostring () + " \ N ------------------------------------------- \ n " ;
}
// Dginfo. Enabled = true;
}
Let's take a look at the output strmessage content:
We can see that the loop contentStrmessage+ = "Loop, before:" +Clstest. itempvalue. tostring ()+ "\ N";
The command is executed twice in total, but the output statement after cell assignment is not executed, as if in the assignment process,ProgramThe variable is automatically reduced by 1, and then the continue is the same, and the 8th rows are exactly the number of rows stopped after the DataGrid is rolled. This can be seen from the result of dragging the scroll bar after the final assignment.