DataGridView, datagridatagridatagri

Source: Internet
Author: User

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>

Related Keywords:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.