DataGridView, datagridatagridatagri
/// <Summary> /// the up and down arrow keys of the DataGridView/// </summary> /// <param name = "dgv"> </param> // <param name = "e"> </param> // <returns> </returns> public static DataGridViewCell datagridview_keyupdowrollrolltorow (DataGridView dgv, keyEventArgs e) {if (e. keyCode = Keys. up) // The Up arrow key {DataGridViewRow dgvCurrentRow = dgv. currentRow; int currentRow = 0; if (dgvCurrentRow! = Null) {if (dgvCurrentRow. index = 0) {currentRow = dgv. rowCount-1;} else {currentRow = dgvCurrentRow. index-1 ;}} return dgv. rows [currentRow]. cells [0];} if (e. keyCode = Keys. down) // downward direction key {maid row dgvCurrentRow = dgv. currentRow; int currentRow = 0; if (dgvCurrentRow! = Null) {if (dgvCurrentRow. index = dgv. rowCount-1) {currentRow = 0;} else {currentRow = dgvCurrentRow. index + 1 ;}} return dgv. rows [currentRow]. cells [0];} return null ;}
C # How does the datagridview cursor position the added row?
Add, delete, and search for the Grid to locate the required line Me. dgvPaper. rows (I ). the Selected = True setting ensures that the Selected row is located at the corresponding position once it is found. If there are many data rows, you want the scroll bar to roll to the corresponding position.
The DataGridView control has a FirstDisplayedScrollingRowIndex attribute. After assigning the row index (N) to this attribute, the first line in the rectangle area of the DataGridView display is the specified line number Me. dgvPaper. firstDisplayedScrollingRowIndex = I
One problem found,
In this way, when CurrentRows is obtained, different rows will appear from Selected rows,
In this way, the setting is OK.
Me. dgvThing. CurrentCell = Me. dgvThing. Rows (I). Cells (0)
The scroll bar automatically scrolls to display the selected row.
Saved
'Me. dgvThing. Rows (0). Selected = False
'Me. dgvThing. Rows (I). Selected = True
'Me. dgvThing. FirstDisplayedScrollingRowIndex = I
C # automatically locates the next row after deleting a row in the datagridview.
Sets an identifier (int indexid) to specify the row to be displayed.
When deleting a row, set indexid to the index of the row to be deleted:
Indexid = maid. Index;
You can set the following settings when updating data to prevent errors in the specified row.
If (indexid <0)
{Indexid = 0 ;}
If (indexid> maid. Rows. Count-1)
{Indexid = indexid-1 ;}
The following sentence specifies the current row of the datagridview
Maid [indexid]. Cells [0];
The following is a method selectionchanged for the datagridview. This function is called when the row selected in the list changes.
Maid selectionchanged (sender, e );
Example:
Int indexid = 0;
/// Delete the Function
Private void btnDel_Click (object sender, EventArgs e)
{
DataGridViewCell cell = maid [0]; // The current row to be deleted
Indexid = maid. Index; // get the Index of the row to be deleted
DataUpdate (sender, e); // The specific function is as follows:
}
/// DataUpdate Function
Private void DataUpdate (object sender, EventArgs e)
{
//// // This location can be data update ///////////////
If (indexid <0)
{Indexid = indexid + 1 ;}
If (indexid> maid. Rows. Count-1)
{Indexid = indexid-1 ;}
DataGridView1.CurrentCell = maid [indexid]. Cells [0]; // note that the indexes in Cells must be visible columns.
Maid selectionchanged (sender, e );
}
/// DataGridView1_SelectionChanged function, which is the control of the datagridveiw... the remaining full text>