Solved

binding

Posted on 2011-02-14
3
261 Views
Last Modified: 2012-05-11
I write the code behind my form in wpf

    Private CustomerData As New CustomerDataSet2
    Private taCust As New CustomerDataSet2TableAdapters.CustomerTableAdapter ' CustomerDataSetTableAdapters.CustomerTableAdapter
    Private taManager As New CustomerDataSet2TableAdapters.TableAdapterManager
    Private View As CollectionView


    Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Me.taCust.Fill(Me.CustomerData.Customer)

        Me.taManager.CustomerTableAdapter = taCust
        MsgBox(Me.taCust.Connection.ConnectionString)

        Me.DataContext = Me.CustomerData.Customer

        Me.View = CollectionViewSource.GetDefaultView(Me.CustomerData.Customer)

    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnFirst.Click
        Me.View.MoveCurrentToFirst()

    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnPrevious.Click
        If Me.View.CurrentPosition > 0 Then
            Me.View.MoveCurrentToPrevious()
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnNext.Click
        If Me.View.CurrentPosition < Me.View.Count - 1 Then
            Me.View.MoveCurrentToNext()
        End If
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLast.Click
        Me.View.MoveCurrentToLast()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnDelete.Click
        If Me.View.CurrentPosition > -1 Then
            Dim row = CType(Me.View.CurrentItem, System.Data.DataRowView).Row
            row.Delete()
        End If
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnAdd.Click
        Dim row = Me.CustomerData.Customer.NewCustomerRow
        row.LastName = "[New]"
        Me.CustomerData.Customer.AddCustomerRow(row)
        Me.View.MoveCurrentToLast()
    End Sub

    Private Sub btnRevert_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnRevert.Click
        If Me.CustomerData.HasChanges Then
            If MessageBox.Show("Are you sure you want to lose all your changes?", Me.Title, MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
                Me.CustomerData.RejectChanges()
            End If
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSave.Click
        Try
            If Me.CustomerData.HasChanges Then
                If Me.taManager.UpdateAll(Me.CustomerData) > 0 Then
                    MsgBox("Saved.")
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Now I need to bind each textbox control with it's field.

It's not success

I am use like this


<TextBox Height="28" Name="txtCustomerID" Width="Auto" IsReadOnly="True" Text="{Binding Path=CustomerID, Mode=OneWay}"/>
            <TextBox Height="28" Name="txtLastName" Width="Auto"  Text="{Binding Path=LastName}"/>
            <TextBox Height="28" Name="txtFirstName" Width="Auto" Text="{Binding Path=FirstName}"/>
            <TextBox Height="28" Name="txtCity" Width="Auto"  Text="{Binding Path=City}"/>
            <TextBox Height="29" Name="Pictrues_locaTextBox" Text="{Binding Path=pictrues_loca, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Width="167" />

How I can do it correctly by programming code ?

0
Comment
Question by:abdallah1973
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 500 total points
ID: 36136968
See my article here on Silverlight to see how Visual Studio helps you in data binding.

http://weblogs.asp.net/nmarun/archive/2009/12/02/using-icommand-silverlight-4.aspx

Arun
0
 

Author Comment

by:abdallah1973
ID: 37365869
No objection
0
 
LVL 27

Expert Comment

by:nmarun
ID: 37365915
'No objection'? care to elaborate?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now