我正在尝试将数据绑定到网格视图,但我在这里遇到了一些问题
Dim bs As New BindingSource
bs.DataSource = (From u In threeContext.dbConext.skechersDeliveries Where u.isprocessed = False Select u).ToList()
dgDeliverys.DataSource = bs
这有效,但当我更新值时,当我离开gridview的行时,它不会保存到数据库中?
答案 0 :(得分:0)
对于你的问题(确保datagridview1.AutoGenerateColumns = True
):
Private Sub DataGridView1_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) _
Handles datagridview1.CellValidating
e.Cancel = Not IsNumeric(DataGridView1.Item(e.ColumnIndex, e.RowIndex))
End Sub
Private Sub DataGridView1_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) _
Handles DataGridView1.DataBindingComplete
For Each col As DataGridViewColumn In DataGridView1.Columns
Select Case col.DataPropertyName
Case "Col1" ' from Table or Linq
col.HeaderText = "My Column 1"
Case "Col2" ' from Table or Linq
col.HeaderText = "My Column 2"
' '' etc for each column
End Select
Next
End Sub