1

我是 wpf 的新手,所以请多多包涵

我为管理“个人资料”记录做了一个窗口

在导航和更新工作时

我似乎也无法让插入工作

这是非常简单的代码

Imports System.Collections.ObjectModel

Public Class Window1
Dim WindowEntities As New DataEntities
Dim WindowList As ObservableCollection(Of Profile)

Function ProfilesViewSource() As CollectionViewSource
    Return CType(FindResource("ProfilesViewSource"), CollectionViewSource)
End Function
Function DefaultView() As CollectionView
    Return CollectionViewSource.GetDefaultView(ProfilesViewSource.View)
End Function

Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles MyBase.Loaded
    WindowList = New ObservableCollection(Of Profile)(From x In WindowEntities.Profiles Order By x.ProfileName)
    ProfilesViewSource.Source = WindowList
End Sub

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnSave.Click
    WindowEntities.SaveChanges()
End Sub

Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnAdd.Click
    WindowList.Add(New Profile)
    DefaultView.MoveCurrentToLast()
End Sub

Private Sub btnNext_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnNext.Click
    DefaultView.MoveCurrentToNext()
End Sub
End Class

当我按添加时,我得到一个新的空记录,当我填写它时,我看到集合看到它,因为有一个显示配置文件的 onform 列表框,它被列在那里,所以它实际上附加到列表中,但 savechanges 命令不会将其插入数据库

插入时可能会出现一些验证错误,但是我会得到一些指示,对吗?现在它只是默默地失败了。好像我从不与提交更改绑定

非常感谢您的帮助研究员

4

1 回答 1

0

(由IVerzin 提供) 1. 创建新的个人资料。2. 将其添加到 WindowEntities 3. 将其添加到 WindowList

于 2011-07-21T12:09:16.480 回答