Although the datagridview datagrihas the verticalscrollbar attribute, It is a protected object and cannot be accessed externally. After reading the attributes of the datagridview, it is found that firstdisplayedscrollingrowindex is the value of the scroll bar, the Row Height of the datagridview multiplied by firstdisplayedscrollingrowindex, which indicates the height of the customer zone.
The following is an example of a vertical scroll bar:
Int _ scrollvalue = 0;
Private void dgvvehicles_scroll (Object sender, scrolleventargs E)
{
If (E. scrollorientation = scrollorientation. verticalscroll)
{
_ Scrollvalue = E. newvalue;
}
}
Private void binddata ()
{
// Set the data source
...
If (dgvvehicles. Rows. Count> _ scrollvalue)
Dgvvehicles. firstdisplayedscrollingrowindex = _ scrollvalue;
}
Another way is to set currentcell. setting this value will cause the dview to jump to the row where the cell is located. The method is to traverse each row to find the unique cell and set it to the current cell.