Update List on Loaded Forms

  • Thread starter Thread starter Kashif Sattar
  • Start date Start date
K

Kashif Sattar

Guest
Hi Everyone,

I have a User Class and 2 Forms with One Datagrid and One Button & TextBox to Save User.

Both Frm as Loaded. Datagrid of Both Forms are Bound with mUser.GetUsers But When I Enter Name of New User and Press Save button Datagrid of same form updates Automatically. But Not Update the Grid of 2nd Form. My Question is How to Automatically Update on Both foms.

Public Class User

Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public ListChangeEvent As New ListChangedEventArgs(ListChangedType.Reset, -1)
Private Access As New DBControl
Private CurrentRecord As Integer = 0
Private _UserID As Integer
Private _UseryName As String
Public _UserList As New List(Of User)

Public Property UserID() As Integer
Get
Return _UserID
End Get
Set(ByVal value As Integer)
_UserID = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(Me.UserID)))
End Set
End Property

Public Property UserName() As String
Get
Return _UseryName
End Get
Set(ByVal value As String)
If IsNumeric(value) = True Then MsgBox("Category Could Not Change ") : Exit Property
_UseryName = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(Me.UserName)))
End Set
End Property

Public Overloads Sub SaveRecord()
Access.AddParam("@d1", Me.UserName)
Access.ExecQuery("Insert into UsersInfo ([UserName]) " &
"Values (@d1);")

If Not String.IsNullOrEmpty(Access.Exception) Then MsgBox(Access.Exception) : Exit Sub
If Access.NoErrors(True) = False Then Exit Sub
XtraMessageBox.Show("Saved Successfully")


OnListChanged(ListChangeEvent)

End Sub


Protected Overridable Sub OnListChanged(ByVal ev As ListChangedEventArgs)
GetUsers()
End Sub

Public Function GetUsers()
' QUERY USER
Access.ExecQuery("SELECT * FROM UsersInfo")

' REPORT & ABORT ON ERRORS OR NO RECORDS FOUND
If Access.NoErrors(True) = False OrElse Access.RecordCount < 1 Then Exit Function

' GET FIRST ROW FOUND
Dim r As DataRow = Access.DBDT.Rows(0)

If _UserList IsNot Nothing Then _UserList.Clear()
For Each r In Access.DBDT.Rows
' POPULATE TEXTBOXES WITH DATA
_UserList.Add(New User With {
.UserID = Convert.ToInt32(r("ID")),
.UserName = r("UserName").ToString
})

Next

Return _UserList
End Function




End Class

Continue reading...
 
Back
Top