2014-04-09 47 views
0

我想数据绑定到网格的看法,但我在这里有一些问题试图数据绑定到GridView的

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

你必须调用threeContext.SaveChanges转发更改源数据库。 –

+0

@AlinI正确的budy我正在调用一个新的dbcontext不能让beleive把一个合适的anser放在他们的感谢之中你不知道如何将gridview条目文本框修改为数字 – rogue39nin

+0

cellvalidating event put:** e.Cancel = Not IsNumeric(e .FormattedValue)** –

回答

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