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