C # control the datagridview in winform. (The button that controls a cell is not displayed, and the readonly of a cell is)

Source: Internet
Author: User

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/


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.