DataGridView operation on the line number

///


///
bottoming out ///

///
/// The row number to be bottomed
public static void BottomDataGridView (DataGridView dataGridView, int index)
{
try
{
DataGridViewSelectedRowCollection dgvsrc = dataGridView.SelectedRows; // Get the collection of selected rows
if (index <dataGridView.Rows.Count- 1) // If the line is not the last line
{
DataGridViewRow dgvr = dataGridView.Rows [index]; // Get the previous line of the selected line
dataGridView.Rows.RemoveAt (index); // Delete the previous line of the originally selected line
int nCount = dataGridView.Rows.Count;
dataGridView.Rows.Insert (nCount, dgvr); // Insert the previous line of the selected line after the selected line
}
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString ());
}
}

// dataGridView1.Rows.Insert (0); insert row
// background color
 dgvDateReport.Rows [i] .Cells [j] .Style.BackColor = Color.FromName ("Red"); // "LightCoral" dark pink / / "Red" red "LightGray" gray
  // font color
  dgvDateReport.Rows [i] .Cells [j] .Style.ForeColor = Color.Red;

Guess you like

Origin www.cnblogs.com/zhujie-com/p/12740003.html