在vb.net中的Datagrid View中编辑 [英] editing in Datagrid View in vb.net
问题描述
我使用sqldatareader / datatable填充了一个datagridview,它有3列。
此外我想在datagridiew中编辑第3列。虽然它允许在第1列进行编辑,但不允许在第2列进行编辑。第3栏。 Plz的帮助。以下是我的代码片段。
私有 Sub cmdGetName_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles cmdGetName.Click
Dim sqlcmd As 新 SqlCommand,reader As SqlDataReader,dTable As New DataTable
sqlcmd.Connection = cnRM
sqlcmd.CommandText = select * from RMPARAS
cnRM.Open()
reader = sqlcmd.ExecuteReader
If reader.H asRows 然后
dTable.Load(reader)
dgv.DataSource = dTable
For 每个列在 dgv.Columns
column.SortMode = DataGridViewColumnSortMode.NotSortable
下一步
dgv。 ReadOnly = 错误
dgv.Refresh()
cnRM.Close()
结束 如果
结束 Sub
< span class =code-keyword>私有 Sub dgv_CellClick( ByVal sender 作为 对象, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellClick
dgv.CurrentCell。 ReadOnly = False
dgv.BeginEdit( False )
结束 Sub
异常抛出
发生错误:上下文:提交:异常:System.Data.ReadOnlyException:列'VALUE'是只读的。
在System.Data.DataRow.set_Item(DataColumn列,对象值)
在System.Data.DataRowView.SetColumnValue(DataColumn列) ,对象值)
在System.Data.DataColumnPropertyDescriptor.SetValue(对象组件,对象值)
在System.Windows.Forms.DataGridView.DataGridViewDataConnection.PushValue(Int32 boundColumnIndex) ,Int32 columnIndex,Int32 rowIndex,Objec t value)
当您尝试更改readonly
[ ^ ]栏。
这里 [ ^ ]是一个可以帮助您解决此问题的指南。
I have populated a datagridview using a sqldatareader / datatable which is having 3 columns.
Further I want to edit 3rd column in datagridiew. Though it is allowing editing in 1st column but not in 2nd & 3rd column. Plz help. Here is snippet of my code.
Private Sub cmdGetName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetName.Click
Dim sqlcmd As New SqlCommand, reader As SqlDataReader, dTable As New DataTable
sqlcmd.Connection = cnRM
sqlcmd.CommandText = "select * from RMPARAS"
cnRM.Open()
reader = sqlcmd.ExecuteReader
If reader.HasRows Then
dTable.Load(reader)
dgv.DataSource = dTable
For Each column In dgv.Columns
column.SortMode = DataGridViewColumnSortMode.NotSortable
Next
dgv.ReadOnly = False
dgv.Refresh()
cnRM.Close()
End If
End Sub
Private Sub dgv_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellClick
dgv.CurrentCell.ReadOnly = False
dgv.BeginEdit(False)
End Sub
Exception thrown is
Error happened : Context : Commit : Exception : System.Data.ReadOnlyException: Column 'VALUE' is read only.
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value)
at System.Data.DataColumnPropertyDescriptor.SetValue(Object component, Object value)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.PushValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex, Object value)
This exception is thrown when you try and change the value of areadonly
[^] column.
Here[^] is a guide that will make you troubleshoot this problem.
这篇关于在vb.net中的Datagrid View中编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!