Friday, June 5, 2009

Binding Source- and Binding navigator

Public Sub New(ByVal NotesSrc As DataSet)
' This call is required by the Windows Form Designer.
InitializeComponent()

Try
dsNotesSrc = NotesSrc
BS = New BindingSource(dsNotesSrc, dsNotesSrc.Tables(0).TableName)
txtNote.DataBindings.Add("Text", BS, dsNotesSrc.Tables(0).Columns("NoteText").ColumnName)

DefaultView = dsNotesSrc.Tables(0).DefaultView

Catch ex As Exception
ex.Message.ToString()
End Try
End Sub

Binding Navigator

Private Sub FrmViewNotes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

lblfrm.Text = "Administrador del sistema"
dsUsers = conFacade.GetUsers()
lblDte.Text = DateTime.Now.ToString()
Me.MdiParent = FrmMDI
ShowUserTo()
BindingNavigatorPositionItem.Text = "Note " & txtNote.BindingContext(DefaultView).Position + 1 & " Of " & txtNote.BindingContext(DefaultView).Count
End Sub

Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click
BS.MoveNext()
ShowUserTo()
BindingNavigatorPositionItem.Text = "Note " & txtNote.BindingContext(BS).Position + 1 & " Of " & txtNote.BindingContext(DefaultView).Count
End Sub

Private Sub BindingNavigatorMoveLastItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveLastItem.Click
BS.MoveLast()
ShowUserTo()
BindingNavigatorPositionItem.Text = "Note " & txtNote.BindingContext(BS).Position + 1 & " Of " & txtNote.BindingContext(DefaultView).Count
End Sub

Private Sub BindingNavigatorMoveFirstItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveFirstItem.Click
BS.MoveFirst()
ShowUserTo()
BindingNavigatorPositionItem.Text = "Note " & txtNote.BindingContext(BS).Position + 1 & " Of " & txtNote.BindingContext(DefaultView).Count
End Sub

Private Sub BindingNavigatorMovePreviousItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMovePreviousItem.Click
BS.MovePrevious()
ShowUserTo()
BindingNavigatorPositionItem.Text = "Note " & txtNote.BindingContext(BS).Position + 1 & " Of " & txtNote.BindingContext(DefaultView).Count
End Sub

Private Sub ShowUserTo()
If txtNote.Text <> "" Then
Dim drNotesSrc() As DataRow = dsNotesSrc.Tables(0).Select("NoteText='" + txtNote.Text + "'")
Dim drUsers() As DataRow = dsUsers.Tables(0).Select("UserId='" + drNotesSrc(0).Item("UserTo").ToString() + "'")
lblTo3.Text = drUsers(0).Item("Name").ToString
Else
lblTo3.Text = String.Empty
End If

End Sub

Private Sub btnDeleteNote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteNote.Click

Dim drNotesSrc() As DataRow = dsNotesSrc.Tables(0).Select("NoteText='" + txtNote.Text + "'")
ParentClass.DeleteNote(drNotesSrc(0).Item("Note").ToString())
dsNotesSrc = BS.DataSource
dsNotesSrc.Tables(0).Rows.RemoveAt(txtNote.BindingContext(BS).Position)
txtNote.DataBindings.Clear()
txtNote.DataBindings.Add("Text", BS, dsNotesSrc.Tables(0).Columns("NoteText").ColumnName)
' BindingNavigatorMovePreviousItem_Click(sender, e)
BindingNavigatorPositionItem.Text = "Note " & txtNote.BindingContext(BS).Position + 1 & " Of " & txtNote.BindingContext(DefaultView).Count


If dsNotesSrc.Tables(0).Rows.Count = 0 Then
ParentClass.MyParent.ViewNoteItemEnabled = False
ParentClass.ImgNotes.Visible = False
Me.Close()

End If--
End Sub

Private Sub btnDeleteall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteall.Click
If dsNotesSrc.Tables(0).Rows.Count <> 0 Then

For i As Integer = 1 To dsNotesSrc.Tables(0).Rows.Count
btnDeleteNote_Click(sender, e)
Next

End If
End Sub

No comments:

Post a Comment