当我更新数据源时,我试图让 datagridview 更新,但我没有任何运气。
这是我的绑定:
Private _dgbNews As SortableBindingList(Of SalesMessageRecord)
Private Sub SalesMessageScreen_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'_dgbNews.RaiseListChangedEvents = True
_dgbNews = AllNews()
BindingSource1.DataSource = AllNews()
DataGridView1.DataSource = BindingSource1
MassageDemRows()
End Sub
这是AllNews()
:
Public Function AllNews() As SortableBindingList(Of SalesMessageRecord)
Dim sm = New SortableBindingList(Of SalesMessageRecord)
Dim allnewsitems = News.GetAllNewsItems(Configuration.CompanyID).ToList()
For Each allnewz As News In allnewsitems
Dim smr = New SalesMessageRecord
smr.Body = allnewz.NewsBody
smr.CorporationId = CType(allnewz.CorporationId, Guid)
smr.Expiration = allnewz.Expiration
smr.IsActive = allnewz.IsActive
smr.NewsId = allnewz.NewsId
smr.Title = allnewz.NewsTitle
smr.SortOrder = allnewz.OrderNumber
smr.TokenId = allnewz.TokenId
smr.IsNew = False
sm.Add(smr)
Next
Return sm
End Function
这就是我试图更新它的地方:
Private Sub button_Save_Click(sender As System.Object, e As System.EventArgs) Handles button_Save.Click
If _currentRow < 0 Then
Return
End If
_dgbNews(_currentRow).Expiration = datetimepicker_ExpirationDate.Value
_dgbNews(_currentRow).SortOrder = CInt(numericupdown_SortNumber.Value)
_dgbNews(_currentRow).IsActive = checkbox_Active.Checked
_dgbNews(_currentRow).Body = richtextbox_Body.Text
_dgbNews(_currentRow).Title = textbox_Title.Text
DataGridView1.Refresh()
News.UpdateNewsRecord(_dgbNews(_currentRow).NewsId,
_dgbNews(_currentRow).Expiration,
_dgbNews(_currentRow).SortOrder,
_dgbNews(_currentRow).IsActive,
_dgbNews(_currentRow).Body,
_dgbNews(_currentRow).Title)
End Sub
数据库正在更新而没有问题,但 datagridview 不会更新。