Private Sub DataGrid1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
If DataGrid1.CurrentCell.ColumnNumber = 8 Then '如果是用户点击第9列
DataGrid1.ReadOnly = False
Else
DataGrid1.ReadOnly = True
End If
end sub
1.第一个问题使用 datagrid的表样式。
Private Function gettablestyle(ByVal tbl As DataTable) As DataGridTableStyle
Dim style1 As New DataGridTableStyle()
style1.MappingName = tbl.TableName
Dim colnumber As Integer = tbl.Columns.Count
Dim i As Integer = 0
Dim col1 As DataGridTextBoxColumn
Dim str As String = "序号,材料编号,材料封度,材料名称,单位,用料数量,欠料数量,买料数量,明细id"
Dim strcaption() As String
strcaption = str.Split(",")
While i < colnumber
col1 = New DataGridTextBoxColumn()
col1.MappingName = tbl.Columns(i).ColumnName
col1.HeaderText = strcaption(i)
col1.NullText = ""
If i = 0 Then
col1.Width = 35
End If
If i < 5 Then
col1.ReadOnly = True ‘设置该列样式关联的列不可修改。
End If
If i = 8 Then
col1.Width = 0
End If
style1.GridColumnStyles.Add(col1)
i = i + 1
End While