WinForm set DataGridView Some rows and columns read-only

Source: Internet
Author: User
Tags rowcount

WinForm set DataGridView Some rows and columns are read-only

The column read-only setting is easier, and the line read-only setting requires that SelectionMode be set to Cellselect,editmode to Editonenter.

   '--datagridview1 control initialization settings (set before data binding, Load event) Private Sub InitDataGrid1 () Me.GridView1.ReadOnly = False        ' Set non-read-only Me.GridView1.SelectionMode = Datagridviewselectionmode.cellselect ' selection mode Me.GridView1.EditMode = Datagridvieweditmode.editonenter ' Enter modify mode (line read only) ' Set column read-only () GridView1. Columns ("column name"). ReadOnly = True ' Sets the column read-only gridview1.columns ("column name"). CellTemplate.Style.BackColor = Color.lavender ' background set gray read-only End Sub '-Sets the DataGrid after binding data (only after setting in INITDATAGRID1 for the DataGrid To control line read only) Private Sub initdatagrid_afterbinddata () If Me.GridView1.RowCount <= 0 Then Return for i as I                                          Nteger = 0 to me.gridview1.rowcount-1 If not me.iscanupdate (i) Then ' If a line cannot edit Me.GridView1.Rows (i). ReadOnly = True ' Sets the line read-only Me.GridView1.Rows (i). Defaultcellstyle.backcolor = Color.Lavender ' background set gray read-only end If Next end Sub 


WinForm set DataGridView Some rows and columns read-only

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.