1: a row in the control button column does not display the button. (Use environment: move data. For example, move the data in the second row to the top. The bottom row is the total row and cannot be moved. Therefore, you need to remove the buttons in the first and last rows. Blocking method: Change the button to a normal cell. ImplementationCodeAs follows: (the button between the first row and the last row in column 8th is not displayed ))
// Define the events before the painting table and convert the buttons into normal cells before painting.
DataGrid. rowprepaint + = maid;
// The button that controls the first and last rows is not displayed.
Private Void Datagrid_rowprepaint ( Object Sender, datagridviewrowprepainteventargs E)
{
If (E. rowindex = 0 | E. rowindex = DataGrid. rowcount- 1 )
{
If (DataGrid [ 7 , E. rowindex] Is Datagridviewbuttoncell)
{
DataGrid [ 7 , E. rowindex] = New Datagridviewtextboxcell ();
DataGrid [ 7 , E. rowindex]. value = String . Empty;
}
}
}
2: controls whether a cell can be modified. (Because the readonly attribute of a cell is not controlled separately, you can only control the attribute by using the technique. The principle is to perform logic processing when determining the incoming cell. If modification is allowed, set readonly to false for the entire table; otherwise, set it to true)
Private Void Datagrid_rowenter ( Object Sender, datagridviewcelleventargs E)
{
If (E. rowindex = DataGrid. rowcount- 1 )
DataGrid. readonly = True ;
Else
DataGrid. readonly = False ;
DataGrid. Columns [ 0 ]. Readonly = True ;
DataGrid. Columns [ 3 ]. Readonly = True ;
}
Original Works are from hard work, please describe them for reprintingArticleSource:Http://blog.csdn.net/kfarvidOrHttp://www.cnblogs.com/kfarvid/